Write an application that accepts a user’s password from the keyboard. When the
ID: 674916 • Letter: W
Question
Write an application that accepts a user’s password from the keyboard. When the entered password has fewer than six characters, more than 10 characters, or does not contain at least one letter and one digit, prompt the user again. When the user’s entry meets all the password requirements, prompt the user to reenter the password, and do not let the user continue until the second password matches the first one. Save the file as Password.java
.
Again, don’t forget to create the application/projectPasswordTest.java Class that has the main method and an object to use the Password class
.
Explanation / Answer
import javax.swing.*;
public class Password
{
public static void main(String[] args)
{
String password = "";
String passwordRepeat = "";
char charBeingChecked = '';
boolean letterPresent = false;
boolean digitPressent = false;
char charChecked;
int len = password.length();
password = JOptionPane.showInputDialog("Enter your password: Must be 6 to 10 characters long Must contain at least one letter and one number");
while((len < 6 || len > 10) || !(password.isLetterorDigit(password)))
{
password = JOptionPane.showInputDialog("Invalid password Please re-enter password");
}
if((len >= 6 || len <= 10) && password.isLetterorDigit(password))
do
{
passwordRepeat = JOptionPane.showInputDialog("Please enter password again to confirm.");
}
while (!(password.equals(passwordRepeat)));
if(password.equals(passwordRepeat))
{
JOptionPane.showMessageDialog(null, "Thank you, now your password is secret.");
}
}
}
import javax.swing.*;
public class Password
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.