Lab 4: Check the Password Before You Wreck the Password
Due by the end of class
Your mission is to write a pro-active password checker that checks to make sure that a user entered password meets certain requirements. You must implement a simple program that prompts the user for two String
values, a password and the same password again for confirmation.
For the purposes of this lab, a legal password must have all of the following properties:
- Length of at least 8 characters
- Starts with a lower case letter
- Ends with a numerical digit
- Is exactly equal to the repetition of the password typed for confirmation
Specification
Create a project called Lab4
. Add a class called Password
.
Complete your program to prompt the user to enter a password and a confirmation as explained above. If the password is shorter than 8 characters, print Password is too short!
Otherwise, if the password does not start with a lower case letter, print Password must start with a lower case letter!
Otherwise, if the password does not end with a digit, print Password must end with a digit!
Otherwise, if the password does not match the confirmation, print Passwords do not match!
Finally, if all the conditions are satisfied, print Password is valid!
To get the length of the password, you will have to use the length()
method on the String
object. To get the first and last characters of the password, you'll have to use the charAt()
method. A lower case letter will be between 'a'
and 'z'
. A digit will be between '0'
and '9'
. Remember that the character values for numerical digits are not the same as the values of the numbers themselves. You will also need to use the equals()
method to compare the two String
values. One of the trickier problems with this lab is that you want to test for the negation of the conditions given above.
Below are several sample cases. The last example is a valid password, but the remainder are not. Try to match the sample output as closely as possible. User input is shown in green. Note that the passwords will be visible, not masked by dots, stars, asterisks, or similar. Making a program mask input is beyond the scope of this class. Note also that you should not test your program with passwords that contain a space since spaces will interfere with the operation of Scanner
input.
Short Password
Enter a password: dang Enter it again: dang Password is too short!
Starts Wrong
Enter a password: Zoomzoom9 Enter it again: Zoomzoom9 Password must start with a lower case letter!
Ends Wrong
Enter a password: tellmeaboutit Enter it again: tellmeaboutit Password must end with a digit!
Doesn't Match
Enter a password: rasputin99 Enter it again: rasputan99 Passwords do not match!
Valid Password
Enter a password: wombat42 Enter it again: wombat42 Password is valid!
Turn In
Turn in your code by uploading Password.java
from the Lab4\src
folder wherever you created your project to Blackboard. Do not upload the entire project. I only want the Password.java
file.
All work must be done individually. Never look at someone else's code. Please refer to the course policies if you have any questions about academic integrity. If you have trouble with the assignment, I am always available for assistance.