In: Computer Science
Write a Java program (name it PasswordTest) that reads from the user a string input (representing a password) and determines whether the password is “Valid Password” or “Invalid Password”. A valid password has at least 7 characters and includes at least one lower-case letter, at least one upper-case letter, at least one digit, and at least one character that is neither a letter nor a digit. Your program will need to check each character in the string in order to render a verdict. For example, CS5000/01 is invalid password; however, Cs5000/01 is a valid password. The program should display the entered password and the judgment as shown in the following sample runs:
Entered Password: CS5000/01
Verdict: Invalid Password
Entered Password: Cs5000/011
Verdict: Valid Password
Entered Password: MyOldDogK9
Verdict: Invalid Password
Entered Password: MyOldDogK9#
Verdict: Valid Password
Entered Password: Ab1#
Verdict: Invalid Password
Document your code, and organize and space out your outputs as shown. Design your program such that it allows the user to re-run the program with different inputs in the same run (i.e., use a sentinel loop structure).
Thanks for the question. Below is the code you will be needing Let me know if you have any doubts or if you need anything to change. Thank You !! =========================================================================== import java.util.Scanner; public class PasswordValidator { public static boolean validPassword(String password) { if (password == null) return false; int length = 0; boolean containLowerCase = false; boolean containsUpperCase = false; boolean containsDigit = false; boolean containsSpecialCharacter = false; for (int i = 0; i < password.length(); i++) { length += 1; char letter = password.charAt(i); if ('a' <= letter && length <= 'z') containLowerCase = true; else if ('A' <= letter && length <= 'Z') containsUpperCase = true; else if ('0' <= letter && letter <= '9') containsDigit = true; else containsSpecialCharacter = true; } return length >= 7 && containLowerCase && containsUpperCase && containsDigit && containsSpecialCharacter; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter Password: "); String password = scanner.nextLine(); if (PasswordValidator.validPassword(password)) { System.out.println("Verdict: Valid Password"); } else { System.out.println("Verdict: Invalid Password"); } } }