When i run this it does not work like its supposed to. Basically the program is a password verifier that checks what the user enters. It works to check for the 6 characters but it does not work correctly to check for the uppercase, lowercase, or the digit.
import javax.swing.JOptionPane;
public class passwordVerifier {
static String input;
char ch;
//prompt user for password
public static void main(String[] args) {
input = JOptionPane.showInputDialog("Please enter a 6 digit password that includes "
+ "at least one uppercase letter, one lowercase letter "
+ "and one numerical digit.");
if(isValid(input)){
JOptionPane.showMessageDialog(null, "That is a valid password.");
}
else{
JOptionPane.showMessageDialog(null, "That is not a valid password.");
}
System.exit(0);
}
private static boolean isValid(String password){
boolean valid = true;
int i = 0;
//verify password has 6 characters
if (password.length()!= 6)
valid = false;
// verify that pasword contains at least one
// uppercase and one lowercase letter
while (valid && i <6){
if (!Character.isUpperCase(password.charAt(i)))
valid = false;
i++;
}
while (valid && i <=6){
if (!Character.isLowerCase(password.charAt(i)))
valid = false;
i++;
}
// verify the password has one digit
while (valid && i <=6){
if (!Character.isDigit(password.charAt(i)))
valid = false;
i++;
}
return valid;
}
}