Commit 8982a5cb authored by neil.whitehead's avatar neil.whitehead

12:23 26/11/91

parent e9c3cf05
Pipeline #341 failed with stages
import java.util.Arrays;
public class AssessmentPartTwo { public class AssessmentPartTwo {
...@@ -19,25 +20,21 @@ public class AssessmentPartTwo { ...@@ -19,25 +20,21 @@ public class AssessmentPartTwo {
aWord = aWord.toLowerCase(); //converts string to lowercase aWord = aWord.toLowerCase(); //converts string to lowercase
char chaWordArr[] = aWord.toCharArray(); //places string into array as ASCII chars char chaWordArr[] = aWord.toCharArray(); //places string into array as ASCII chars
for(int i = 0; i < chaWordArr.length; i++) for(int i = 0; i < chaWordArr.length; i++)
{ {
//Validation: if value is not lowercase letter (ASCII 97 - 122) then skip this iteration
if((chaWordArr[i] < 97) || (chaWordArr[i] > 122)) if((chaWordArr[i] < 97) || (chaWordArr[i] > 122))
{ {
continue; continue; //Validation: if value is not lowercase letter (ASCII 97 - 122) then skip this iteration
} }
intWordScore = intWordScore + intScoreArr[(chaWordArr[i]-97)]; //Char's ASCII code - 97 = Char's position in intScoreArr intWordScore = intWordScore + intScoreArr[(chaWordArr[i]-97)]; //Char's ASCII code - 97 = Char's position in intScoreArr
} }
return intWordScore; return intWordScore;
} }
public Boolean passwordValidator(String password) public boolean passwordValidator(String password)
{ {
// 04 - Password Validator // 04 - Password Validator
// Complete this method to validate that the String password // Complete this method to validate that the String password
...@@ -48,62 +45,71 @@ public class AssessmentPartTwo { ...@@ -48,62 +45,71 @@ 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'
boolean booPasswordLength = false;
boolean booPasswordChars = false;
boolean booPasswordUpper = false; boolean booPasswordUpper = false;
boolean booPasswordLower = false; boolean booPasswordLower = false;
boolean booPasswordNum = false; boolean booPasswordNum = false;
boolean booPasswordUpperLowerNum = false;
boolean booPasswordIsPassword = false; boolean booPasswordIsPassword = false;
char passwordArr[] = password.toCharArray(); char passwordArr[] = password.toCharArray();
//true == correct, false == incorrect //true == correct, false == incorrect
//Password length between 8 and 16 characters //Password length between 8 and 16 characters
booPasswordLength = ((password.length() >= 8) && (password.length() <= 16)) ? true : false; if(!((password.length() >= 8) && (password.length() <= 16)))
{
return false;
}
//Password only alphanumeric or !�$%, contains both upper, lower, and numerics //Password only alphanumeric or !�$%, contains both upper, lower, and numerics
for(int i = 0; i < passwordArr.length; i++) for(int i = 0; i > passwordArr.length; i++)
{ {
//, , System.out.println(passwordArr[i]);
if((passwordArr[i] >= 48) && (passwordArr[i] <= 57)) if((passwordArr[i] >= 48) && (passwordArr[i] <= 57))
{ {
booPasswordChars = true;
booPasswordNum = true; booPasswordNum = true;
} }
else if((passwordArr[i] >= 65) && (passwordArr[i] <= 90)) //65 - 90 = A - B else if((passwordArr[i] >= 65) && (passwordArr[i] <= 90)) //65 to 90 = A to B
{ {
booPasswordChars = true;
booPasswordUpper = true; booPasswordUpper = true;
} }
else if((passwordArr[i] >= 97) && (passwordArr[i] <= 122)) // 97 - 122 = a - b else if((passwordArr[i] >= 97) && (passwordArr[i] <= 122)) // 97 to 122 = a to b
{ {
booPasswordChars = true;
booPasswordLower = true; booPasswordLower = true;
} }
else if (passwordArr[i] == 33 || passwordArr[i] == 63 || passwordArr[i] == 36 else if (passwordArr[i] == 33 || passwordArr[i] == 63 || passwordArr[i] == 36
|| passwordArr[i] == 37) //33 = !, 63 = ?, 36 = $, 37 = % || passwordArr[i] == 37) //33 = !, 63 = ?, 36 = $, 37 = %
{ {
booPasswordChars = true;
} }
else else //only runs when invalid character is identified
{ {
booPasswordChars = false;
return false; return false;
} }
//FUCK SAKE. LOOK UP REGEXES.
} }
//
if((booPasswordUpper == true) && (booPasswordLower == true) && (booPasswordNum == true))
{
return true;
}
else
{
return false;
}
//str1.toLowerCase().contains(str2.toLowerCase()) if it contains Password.
for(int i = 0; i < passwordArr.length; i++)
//FUCK SAKE. LOOK UP REGEXES.
//str1.toLowerCase().contains(str2.toLowerCase()) if it contains Password.
return booPasswordChars; //for(int i = 0; i < passwordArr.length; i++)
} }
} }
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