Commit 3a5d33be authored by samuelboulton's avatar samuelboulton

Unit test passed and comments added

parent e52b3223
......@@ -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
// 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 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"))
// 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
{
return false;
validator = 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)
// if statement for when the validator turns true
if(validator == true)
{
return false;
}
// if statement to see if there is a lower cased letter in the password
if(!password.matches(lowerCase))
// check to see if the password has this phrase in it
if(!password.contains("passwd"))
{
return false;
}
// if statement to see if there is a upper cased letter in the password
if(!password.matches(upperCase))
// check to see if the password has this phrase in it
if(!password.contains("password"))
{
return false;
}//hello
// if statement to see if there is a number in the password
if(!password.matches(numbers))
// make sure the password is between 8-16 letters long
if(password.length() <= 16 && password.length() >= 8)
{
return false;
}
if(password.contains("!") || password.contains("�") || password.contains("$") || password.contains("%"))
// 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;
}
else
// otherwise each one will return false.
else{return false;}
}
else{return false;}
}
else{return false;}
}
else{return false;}
}
else{return false;}
}
else{return false;}
}
// when the validator is false it will return false.
if(validator == false)
{
return true;
return false;
}
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment