Reference no: EM132161809
As a developing software need to require enter own password as a following criteria:
a). The program should display one of three rankings for the password provided by the user:
INVALID, ACCEPTABLE, STRONG.
b). The password is ACCEPTABLE if it meets the following criteria, INVALID if it does not:
- At least six (6) characters in length.
- Contains at least one (1) uppercase letter and one (1) lowercase letter.
- Contains at least one (1) numerical digit.
- Contains at least one of the following special characters: ! @ # $ % ^ & * . ?
- (hint: Need to create the array to hold these characters)
c). If the password is INVALID, your program should display the reason(s) why.
- the password "Tasbih15" is invalid because it is missing a special character.
- the password "b@buza" is invalid because it is missing an uppercase letter AND a numerical digit.
- Missing any requirements, please list missing item(s).
d). The password is STRONG if it is at least 10 characters in length and contains at least two (2) special characters.
## Here is my code:
import javax.swing.JOptionPane;
public class AktaruzzamanPasswordVerifier {
public static void main(String[] args) {
String input;
char[] array;
// Get the user to enter a password to use
input = JOptionPane.showInputDialog("Enter " +
"the password that is at least 6 characters long,n " +
"contains at least 1 uppercase letter, containsn " +
"at least 1 lowercase letter, and containsn " +
"and at least 1 digit.");
// Validate the input.
if (isValid(input))
{
JOptionPane.showMessageDialog(null,
"This is a valid password.");
}
else
{
JOptionPane.showMessageDialog(null,
"That is not the proper format of a " +
"password.nHere is an" +
"example: taS5by");
// user to re-enter a password to use
input = JOptionPane.showInputDialog("Enter " +
"The password that is at least 6 characters long,n " +
"contains at least 1 uppercase letter, containsn " +
"at least 1 lowercase letter, and containsn " +
"and at least 1 digit.");
}
System.exit(0);
}
private static boolean isValid(String userPassword)
{
boolean goodSoFar = true;
int i = 0;
// Test the password length.
if (userPassword.length() < 6)
goodSoFar = false;
JOptionPane.showMessageDialog(null, "Password invalid. Must contain at least 6 characters");
// Test the password at least 1 upper case letter
while(goodSoFar)
{
if (!Character.isUpperCase(userPassword.charAt(i)))
goodSoFar = false;
System.out.println("No uppercase");
i++;
}
// Test the password at least 1 lower case letter
while(goodSoFar)
{
i = 0;
if (!Character.isLowerCase(userPassword.charAt(i)))
goodSoFar = false;
System.out.println("No lowercase");
i++
}
// Test the password at least 1 numeric digit letter
while(goodSoFar)
{
i = 0;
if (!Character.isDigit(userPassword.charAt(i)))
goodSoFar = false;
System.out.println("No numeric");
i++;
}
return goodSoFar;
}
}