Commit b5dd4d0d authored by rehman.khan's avatar rehman.khan

assess2

parent 01df26df
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;
}
}
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