Hello,
I'm new to programming and am having a problem with my homework assignment. Some parts will work but I can't figure out how I've used some loops, methods and such incorrectly. The for loop and the if statements that contain matches are not working and I am at a loss as to why. Any help would be greatly appreciated!
import java.util.Scanner; public class PasswordVerifier { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); String newPassword; //user input boolean legalPassword = true; // is the user input legal? boolean rightLength = true; //determines correct length boolean uCase = true; // Has upper case boolean lCase = true; // has lower case boolean sCase = true; // has special character boolean digit = true; // has a number boolean noContainCase = true; // doesn't have and or end //newPassword print statement System.out.print("Password Verifier\n"); System.out.print("\nEnter a password that meets the following rules: \n\n" + "\tIs at least 8 characters long\n" + "\tContains at least 1 upper case letter\n" + "\tContains at least 1 lower case letter\n" + "\tContains at least 1 numeric digit\n" + "\tContains at least 1 of the following: !@#$%^&*\n" + "\tDoes not contain the words \"and\" or \"end\"\n" ); newPassword = stdIn.nextLine(); // user input // newPassword conditions if (newPassword.length() < 8) { rightLength = false; legalPassword = false; } for (int i = 0; i < newPassword.length(); i++) { if (!(Character.isUpperCase(newPassword.charAt(i)))); { uCase = false; legalPassword = false; i++; } if (!(Character.isLowerCase(newPassword.charAt(i)))); { lCase = false; legalPassword = false; i++; } if (!(Character.isDigit(newPassword.charAt(i)))); { digit = false; legalPassword = false; i++; } } String specialCh = "(.*!,@,#,$,%,^,&,*.*)"; if (!(newPassword.matches(specialCh))) { sCase = false; legalPassword = false; } String noContain = "(.*and, end.*)"; if (!(newPassword.matches(noContain))) { noContainCase = false; legalPassword = false; } if (legalPassword) { System.out.print("Valid"); } else if (legalPassword != true) { System.out.print("Invalid\n"); } // Print statements if (rightLength != true) { System.out.print("Password must be at least 8 characters long\n"); } if (uCase != true) { System.out.print("Must contain an upper case letter\n"); } if (lCase != true) { System.out.print("Must contain a lower case letter\n"); } if (digit != true) { System.out.print("Must contain a digit\n"); } if (sCase != true) { System.out.print("Must contain a special character from the list\n"); } if (noContainCase != true) { System.out.print("Must not contain \"and\" or \"end\""); } } }