You are viewing a single comment's thread. Return to all comments →
Java and O(n)
Set<Character> specialCharacters = new HashSet<>(Arrays.asList('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+')); boolean hasDigit = false; boolean hasLowercase = false; boolean hasUppercase = false; boolean hasSpecialCharacter = false; int additionsNeeded = 0; for (char c : password.toCharArray()) { if (Character.isDigit(c)) hasDigit = true; else if (Character.isLowerCase(c)) hasLowercase = true; else if (Character.isUpperCase(c)) hasUppercase = true; else if (specialCharacters.contains(c)) hasSpecialCharacter = true; } if (!hasDigit) additionsNeeded++; if (!hasLowercase) additionsNeeded++; if (!hasUppercase) additionsNeeded++; if (!hasSpecialCharacter) additionsNeeded++; return Math.max(additionsNeeded, 6 - n);
Seems like cookies are disabled on this browser, please enable them to open this website
Strong Password
You are viewing a single comment's thread. Return to all comments →
Java and O(n)