Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment 2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rehman.khan
Assessment 2
Commits
b5dd4d0d
Commit
b5dd4d0d
authored
Jan 11, 2019
by
rehman.khan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
assess2
parent
01df26df
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
2 deletions
+43
-2
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+43
-2
No files found.
src/AssessmentPartTwo.java
View file @
b5dd4d0d
import
java.util.regex.Pattern
;
public
class
AssessmentPartTwo
{
...
...
@@ -24,11 +25,51 @@ public class AssessmentPartTwo {
// is a valid password
// A password is valid if it is
// - between 8 and 16 characters long (inclusive)
// - made up of letters (upper or lower), numbers, and the following characters !£$%
// - made up of letters (upper or lower), numbers, and the following characters !
�
$%
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
return
false
;
Pattern
specialCharPatten
=
Pattern
.
compile
(
"[^a-z0-9 ]"
,
Pattern
.
CASE_INSENSITIVE
);
Pattern
UpperCasePatten
=
Pattern
.
compile
(
"[A-Z ]"
);
Pattern
lowerCasePatten
=
Pattern
.
compile
(
"[a-z ]"
);
Pattern
digitCasePatten
=
Pattern
.
compile
(
"[0-9 ]"
);
//uses the java.util from java when it compares every letter of the PASSWORD
// uses java.util from java to complete a search for any upper case letters
//uses the java.util. from java to complete a search for lower case letter
//uses the java from java to search for any numbers and special characters
boolean
flag
=
true
;
//it makes the final result a boolean variable to use in every statement
if
((
password
.
length
()
<
8
)
&&
(
password
.
length
()
>
16
))
{
flag
=
false
;
//ensures password is between 8-16 characters if not returns false
}
if
(!
specialCharPatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//completes a search for any special characters or words E.G. password
//if not returns false
}
if
(!
UpperCasePatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//search to see if thgere is any upper case letters in the password
if
(!
lowerCasePatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//search o see if there is any lower case letters in the password
}
if
(!
digitCasePatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//search the password to see if it includes any numbers, if not returns false
}
return
flag
;
//returns final statement if password is valid or not.
}
return
flag
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment