Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program called PasswordValidationYourLastName that validates a new password, following these guidelines: Must be at least 8 characters Must have at least 1 uppercase

Write a program called PasswordValidationYourLastName that validates a new password, following these guidelines:

  • Must be at least 8 characters
  • Must have at least 1 uppercase letter
  • Must have at least 1 lowercase letter
  • Must have at least 1 digit

Write a program that asks for a password, and then asks again to confirm it (you can use the scanner or JOptionPane) in the main method. Pass those two Strings to a method called validatePassword( ). Your validatePassword( ) should return a boolean - true if the passwords pass validation and false if the passwords do not pass validation.

If the passwords dont meet validation rules, respond to the user that the passwords do not meet validation rules. If the passwords meet validation rules, return Password changed and exit the program. Your validatePassword( ) method will check to see if the two passwords passed in are valid. All of the checks should happen in the method.

Right off the bat in your method, you should automatically return false if the passwords are not the same.

Again, if they are less than 8, then you can immediately return false too.

If the passwords are the same, then begin your checks listed above. You could use booleans variables as flags to keep track whether you've found an uppercase, lowercase and digit.

You can use isUpperCase(), isLowerCase(), isDigit() to check to see if something is a digit, uppercase or lowercase in the String.

After looking at the string, if all of your boolean variables are true (meaning you've found them), then you know your passwords are good.

Is there a reason to compare both passwords if they are the same? No. So just run your checks through one variable.

Again: use a boolean as your return type in the method. If any of the components are not met, change the boolean to false. Once the boolean is set to false, you know the password was not valid and you can return that to your main method as false to tell them that the passwords are not valid.

Use my tester file provided below to test your Password Validation method. You will have to change the name of the class in the tester but the method should pass.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions