Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AssessmentP2
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
samuel.boulton
AssessmentP2
Commits
3a5d33be
Commit
3a5d33be
authored
Dec 03, 2018
by
samuelboulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit test passed and comments added
parent
e52b3223
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
40 deletions
+105
-40
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+105
-40
No files found.
src/AssessmentPartTwo.java
View file @
3a5d33be
...
...
@@ -98,51 +98,116 @@ public class AssessmentPartTwo {
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
// Declaring each String for which is allowed and which isn't allowed
// .matches() is used to see if the password matches these statements
String
lowerCase
=
"(.*[a-z].*)"
;
String
upperCase
=
".*[A-Z].*"
;
String
numbers
=
".*[0-9].*"
;
String
symbols
=
".*[!�$%].*"
;
// if statement and contains() method to see if the password contains these phrases
if
(
password
.
contains
(
"passwd"
))
{
return
false
;
}
// if statement and contains() method to see if the password contains these phrases
if
(
password
.
contains
(
"password"
))
{
return
false
;
}
// if statement to make sure the length is between 16 and 8 letters long
if
(
password
.
length
()
>
16
||
password
.
length
()
<
8
)
{
return
false
;
}
// if statement to see if there is a lower cased letter in the password
if
(!
password
.
matches
(
lowerCase
))
// Declaring a boolean variable for a true of false output for an if statement
boolean
validator
=
false
;
// String for lower-case numbers for .matches() method
String
lowerCase
=
"(.*[a-z].*)"
;
// String for upper-case numbers for .matches() method
String
upperCase
=
"(.*[A-Z].*)"
;
// String for upper-case numbers for .matches() method
String
numbers
=
"(.*[0-9].*)"
;
// for loop to go through the length of the password
for
(
int
i
=
0
;
i
<
password
.
length
();
i
++)
{
// changes each loop into a char and puts them into 'parts'
char
parts
=
password
.
charAt
(
i
);
// if statement to find out if the password has any of these symbols in them
if
(
parts
==
'!'
||
parts
==
'�'
||
parts
==
'%'
||
parts
==
'$'
)
// if the if statement is correct the boolean validator becomes true
{
validator
=
true
;
}
// if statement to make sure that the password doesn't have anymore symbols other than the ones above.
if
(
parts
==
'a'
||
parts
==
'A'
||
parts
==
'b'
||
parts
==
'B'
||
parts
==
'c'
||
parts
==
'C'
||
parts
==
'd'
||
parts
==
'D'
||
parts
==
'e'
||
parts
==
'E'
||
parts
==
'f'
||
parts
==
'F'
||
parts
==
'g'
||
parts
==
'G'
||
parts
==
'h'
||
parts
==
'H'
||
parts
==
'i'
||
parts
==
'I'
||
parts
==
'j'
||
parts
==
'J'
||
parts
==
'k'
||
parts
==
'K'
||
parts
==
'l'
||
parts
==
'L'
||
parts
==
'm'
||
parts
==
'M'
||
parts
==
'n'
||
parts
==
'N'
||
parts
==
'o'
||
parts
==
'O'
||
parts
==
'p'
||
parts
==
'P'
||
parts
==
'q'
||
parts
==
'Q'
||
parts
==
'r'
||
parts
==
'R'
||
parts
==
's'
||
parts
==
'S'
||
parts
==
't'
||
parts
==
'T'
||
parts
==
'u'
||
parts
==
'U'
||
parts
==
'v'
||
parts
==
'V'
||
parts
==
'w'
||
parts
==
'W'
||
parts
==
'x'
||
parts
==
'X'
||
parts
==
'y'
||
parts
==
'Y'
||
parts
==
'z'
||
parts
==
'Z'
||
parts
==
'0'
||
parts
==
'1'
||
parts
==
'2'
||
parts
==
'3'
||
parts
==
'4'
||
parts
==
'5'
||
parts
==
'6'
||
parts
==
'7'
||
parts
==
'8'
||
parts
==
'9'
)
// if parts only include those symbols and these char's then the validator turns true
{
validator
=
true
;
}
// otherwise its false
else
{
validator
=
false
;
}
}
// if statement for when the validator turns true
if
(
validator
==
true
)
{
return
false
;
// check to see if the password has this phrase in it
if
(!
password
.
contains
(
"passwd"
))
{
// check to see if the password has this phrase in it
if
(!
password
.
contains
(
"password"
))
{
// make sure the password is between 8-16 letters long
if
(
password
.
length
()
<=
16
&&
password
.
length
()
>=
8
)
{
// if statement to show the password has at least a lower-case letter in it
if
(
password
.
matches
(
lowerCase
))
{
// if statement to show the password has at least a upper-case letter in it
if
(
password
.
matches
(
upperCase
))
{
// if statement to make sure the password has at least 1 number in it
if
(
password
.
matches
(
numbers
))
{
// iff all correct it will return true.
return
true
;
}
// otherwise each one will return false.
else
{
return
false
;}
}
else
{
return
false
;}
}
else
{
return
false
;}
}
else
{
return
false
;}
}
else
{
return
false
;}
}
else
{
return
false
;}
}
//
if statement to see if there is a upper cased letter in the password
if
(
!
password
.
matches
(
upperCase
)
)
//
when the validator is false it will return false.
if
(
validator
==
false
)
{
return
false
;
}
//hello
// if statement to see if there is a number in the password
if
(!
password
.
matches
(
numbers
))
{
return
false
;
}
if
(
password
.
contains
(
"!"
)
||
password
.
contains
(
"�"
)
||
password
.
contains
(
"$"
)
||
password
.
contains
(
"%"
))
{
return
true
;
}
else
{
return
true
;
}
}
return
false
;
}
}
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