Question: Project 3: Check Password Problem Description: Suppose a website impose the following rules for passwords. A password must have at least eight characters. A password
Project 3: Check Password
Problem Description:
Suppose a website impose the following rules for passwords.
A password must have at least eight characters.
A password consists of only letters and digits.
A password must contain at least two digits.
Write a program that prompts the user to enter a password. If the user enters an invalid password, the program needs to tell the user why it is invalid and ask the user to enter another password. The program should stop only when the user enters a valid password.
Here is one sample run to check these 4 passwords in order (My password18 -> pass18 -> password -> Mypassword18):
Enter a new password: My password18
Invalid: Only letters and digits
Enter a new password: pass18
Invalid: Too Few Characters (8 at least)
Enter a new password: password
Invalid: At least two digits
Enter a new password: Mypassword18
Valid password!
Hints:
Start small.
Try to add one rule at a time. Make sure this rule is implemented correctly before adding the next one.
Make your program work for handling one password first. Then, add the while loop to handle potentially multiple passwords so that the program will stop only when a valid password is typed. (Example code of Slide 44 in Chapter 5)
For a password that violates multiple rules, you only need to let the user know the first rule that is violated.
Utilize the Eclipse debugger to make sure your code is running correctly.
Suppose ch takes one character, you can use Character.isLetterOrDigit(ch) to check if ch is letter or digit. Moreover, you can use Character.isDigit(ch) to check if ch is a digit; increase the count of digits by one only when one digit is found.
What to deliver?
Your .java file including:
Your code with other appropriate comments. (Code: 5 points, Comments: 3 points)
One sample run to type the follow four passwords in order (pasted and commented out at top): (2 points)
pw -> password -> itss 3211 -> itss3211
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
