Instantly share code, notes, and snippets.

@benjholla /Puzzle20.java Secret
Created Oct 31, 2018

Embed
What would you like to do?
Java Puzzle 20 (Evaluate the password strategies)
public class Puzzle20 {
public static void main(String[] args) {
System.out.println("Which password strategy is more secure?");
}
/**
* For your security, passwords must follow these requirements:
* Passwords must be 8 characters in length.
* Passwords must include at least one letter (a-z, A-Z) or supported special character (@, #, $ only).
* Passwords must include at least one number (0-9).
* Passwords cannot contain spaces or unsupported special characters.
* Passwords previously used cannot be re-used.
* @return
*/
private static boolean checkPasswordStrategy1(String pw) {
boolean isEightChars = pw.length() == 8;
boolean hasUppercase = !pw.equals(pw.toLowerCase());
boolean hasLowercase = !pw.equals(pw.toUpperCase());
boolean hasSpecial = pw.contains("@") || pw.contains("#") || pw.contains("$");
boolean noUnsupported = pw.replaceAll("[A-Za-z0-9]*", "")
.replace("@", "").replace("#", "").replace("$", "").length() == 0;
return isEightChars && hasUppercase && hasLowercase && hasSpecial && noUnsupported;
}
private static boolean checkPasswordStrategy2(String pw) {
return pw.length() >= 8 && pw.length() <= 100;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment