public static boolean isValid(String password) {
Boolean atleastOneUpper = false;
Boolean atleastOneLower = false;
Boolean atleastOneDigit = false;
// If its less then 8 characters, its automatically not valid
if (password.length() < 8) {
return false;
}
for (int i = 0; i < password.length(); i++) {
// Lets iterate over only once.
if (Character.isUpperCase(password.charAt(i))) {
atleastOneUpper = true;
}
else if (Character.isLowerCase(password.charAt(i))) {
atleastOneLower = true;
}
else if (Character.isDigit(password.charAt(i))) {
atleastOneDigit = true;
}
}
return (atleastOneUpper && atleastOneLower && atleastOneDigit);
// Return true if the password is atleast eight characters long, has atleast one upper, lower and digit
}