Commit 3a5d33be authored by samuelboulton's avatar samuelboulton

Unit test passed and comments added

parent e52b3223
...@@ -98,51 +98,116 @@ public class AssessmentPartTwo { ...@@ -98,51 +98,116 @@ public class AssessmentPartTwo {
// - has at least one lower case letter, one upper case letter and a number // - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd' // - does not contain the phrases 'password' or 'passwd'
// Declaring each String for which is allowed and which isn't allowed // Declaring a boolean variable for a true of false output for an if statement
// .matches() is used to see if the password matches these statements boolean validator = false;
String lowerCase = "(.*[a-z].*)"; // String for lower-case numbers for .matches() method
String upperCase = ".*[A-Z].*"; String lowerCase = "(.*[a-z].*)";
String numbers = ".*[0-9].*"; // String for upper-case numbers for .matches() method
String symbols = ".*[!�$%].*"; String upperCase = "(.*[A-Z].*)";
// if statement and contains() method to see if the password contains these phrases // String for upper-case numbers for .matches() method
if(password.contains("passwd")) String numbers = "(.*[0-9].*)";
{
return false; // for loop to go through the length of the password
} for(int i = 0; i < password.length(); i++)
// if statement and contains() method to see if the password contains these phrases {
if(password.contains("password")) // changes each loop into a char and puts them into 'parts'
{ char parts = password.charAt(i);
return false; // if statement to find out if the password has any of these symbols in them
} if(
// if statement to make sure the length is between 16 and 8 letters long parts == '!'|| parts == '�'
if(password.length() > 16 || password.length() < 8) || parts == '%'|| parts == '$')
{ // if the if statement is correct the boolean validator becomes true
return false; {
} validator = true;
// if statement to see if there is a lower cased letter in the password }
if(!password.matches(lowerCase)) // 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 // when the validator is false it will return false.
if(!password.matches(upperCase)) if(validator == false)
{ {
return 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 false;
{ }
return true;
}
}
} }
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