Commit 84d2d7e1 authored by neil.whitehead's avatar neil.whitehead

12:19 10/12/18

parent 8982a5cb
import static org.junit.Assert.assertThat;
import java.util.Arrays;
public class AssessmentPartTwo {
public class AssessmentPartTwo
{
public static void main(String[] args)
{
System.out.println(passwordValidator("lo98passwdiI"));
}
public int scrabbleScore(String aWord)
{
......@@ -20,21 +29,25 @@ public class AssessmentPartTwo {
aWord = aWord.toLowerCase(); //converts string to lowercase
char chaWordArr[] = aWord.toCharArray(); //places string into array as ASCII chars
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))
{
continue; //Validation: if value is not lowercase letter (ASCII 97 - 122) then skip this iteration
}
continue;
}
intWordScore = intWordScore + intScoreArr[(chaWordArr[i]-97)]; //Char's ASCII code - 97 = Char's position in intScoreArr
}
return intWordScore;
}
public boolean passwordValidator(String password)
public static Boolean passwordValidator(String password) //REMEMBER TO TAKE OUT STATIC
{
// 04 - Password Validator
// Complete this method to validate that the String password
......@@ -45,71 +58,110 @@ 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'
boolean booPasswordUpper = false;
boolean booPasswordLower = false;
boolean booPasswordNum = false;
boolean booPasswordIsPassword = false;
boolean booUpper = false; //Uppercase present
boolean booLower = false; //Lowercase present
boolean booNum = false; //Number present
char passwordArr[] = password.toCharArray();
//true == correct, false == incorrect
String[] strMustNotContain = new String[] {"password", "passwd"};
//Password length between 8 and 16 characters
if(!((password.length() >= 8) && (password.length() <= 16)))
{
if((password.length() < 8) || (password.length() > 16))
{
System.out.println(password.length());
return false;
}
}
//Password does not contain. . .
//Password only alphanumeric or !�$%, contains both upper, lower, and numerics
for(int i = 0; i > passwordArr.length; i++)
for(int i = 0; i < strMustNotContain.length; i++)
//selects banned words from array
{
System.out.println(passwordArr[i]);
if((passwordArr[i] >= 48) && (passwordArr[i] <= 57))
if((password.toLowerCase().contains(strMustNotContain[i])))
{
booPasswordNum = true;
return false;
}
else if((passwordArr[i] >= 65) && (passwordArr[i] <= 90)) //65 to 90 = A to B
{
booPasswordUpper = true;
}
//Password only alphanumeric or !�$%, contains both upper, lower, and numerics
for(int i = 0; i < passwordArr.length; i++)
{
if((passwordArr[i] >= 48) && (passwordArr[i] <= 57))
{ //48 to 57 = 0 to 9
booNum = true;
}
else if((passwordArr[i] >= 97) && (passwordArr[i] <= 122)) // 97 to 122 = a to b
{
booPasswordLower = true;
else if((passwordArr[i] >= 65) && (passwordArr[i] <= 90))
{ //65 to 90 = A to B
booUpper = true;
}
else if((passwordArr[i] >= 97) && (passwordArr[i] <= 122))
{ // 97 to 122 = a to b
booLower = true;
}
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 = %
}
else //only runs when invalid character is identified
{
return false;
}
}
//
if((booPasswordUpper == true) && (booPasswordLower == true) && (booPasswordNum == true))
{
return true;
else
{ //if Char is not valid
return false;
}
}
else
{
return false;
if((booNum == false) || (booUpper == false) || (booLower == false))
{ //if password does not contain Num, Upper, or Lower Chars
return false;
}
//FUCK SAKE. LOOK UP REGEXES.
//FUCK SAKE. LOOK UP REGEXES.
//str1.toLowerCase().contains(str2.toLowerCase()) if it contains Password.
/* Legacy code that I want to keep if I ever look back on this
//for(int i = 0; i < passwordArr.length; i++)
}
//Password does not contain Password or Passwd
for(int i1 = 0; i1 < strMustNotContain.length; i1++)
//selects banned words from array
{
System.out.println("Is " + strMustNotContain[i1].toString() + " in " + password + "?");
for(int i2 = 0; i2 < (passwordArr.length - strMustNotContain[i1].length() + 1); i2++)
{
//cycles through password
char[] comparisonArr = new char[strMustNotContain[i1].length()];
for(int i3 = 0; i3 < strMustNotContain[i1].length(); i3++)
//populates a sample from password which is the same length as banned word
{
comparisonArr[i3] = Character.toLowerCase(passwordArr[i3 + i2]);
//i2 represents the offset of the sample from password, i3 the position within the sample
}
String strComparison = new String(comparisonArr);
//from array to string
System.out.println("Banned word: " + strMustNotContain[i1] + " sample: " + strComparison);
System.out.println(strComparison.equals(strMustNotContain[i1]));
if(strComparison.equals(strMustNotContain[i1]))
//comparison between sample from password to banned word
{
System.out.println("MATCH");
return false;
}
else
{
System.out.println("not a match");
}
}
}
*/
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