The issue I am having is when someone enters a password that includes digits, uppercase, and lowercase the program still says they need all them.
I need the program to list all the requirements for a password if they are not met.
For example:
A123456789aa returns: "You need at least one lowercase. Please Enter Your Password:"
It should return: "Enter termination key"
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
boolean condition = true;
while (condition) {
System.out.print("Please Enter Your Password: ");
String password = input.nextLine();
if (password.equals("endofinput")) {
System.out.print("Your password is valid"); condition = false;
} else {
System.out.print(passCheck(password));
condition = true;
}
}
input.close();
}
public static String passCheck(String password) {
String specialChars = "/*!@#$%^&*()\"{}_[]|\\?/<>,." + " ";
if (password.length() < 8) {
return ("You need at least 8 characters. ");
} for (int i = 0; i < password.length(); i++) {
if (specialChars.contains(password.substring(i)))
return ("Your password cannot contain special characters. ");
else if (password.equals("password"))
return ("Your password cannot be password. ");
else if(!Character.isUpperCase(password.charAt(i)))
return ("You need at least one uppercase. ");
else if (!Character.isLowerCase(password.charAt(i)))
return ("You need at least one lowercase. ");
else if (!Character.isDigit(password.charAt(i)))
return ("You need at least one digit. ");
}
return "Enter termination key";
}