I am trying to create a program that will take input from user as a password and compare to see if the password meets the requirements. If it doesn't meet requirements, re-prompt user for password again until it meets the requirements. Here is what I have and I don't understand why it doesn't work...
import javax.swing.*;
public class Password {
public static void main(String[] args) {
//
String pInput = "";
do {
pInput = JOptionPane.showInputDialog(null, "Please enter your password.\n"
+ "Your password must have 6-10 characters\n"
+ "Your password must contain at least one letter and one digit");
}
while (authenticate(pInput) == false);
JOptionPane.showMessageDialog(null, "Your password was successfully entered.");
}
private static boolean authenticate(String password)
{
// The password should be at least six characters long.
// The password should contain at least one letter.
// The password should have at least one digit.
if ((password.length() > 6) &&
(password.length() < 10) &&
(password.matches("[a-z]")) &&
(password.matches("[0-9]")))
return true;
else
return false;
}
}