Ask Question
14 May, 08:05

Write an application that prompts the user for a password that contains at least two uppercase letters, at least three lowercase letters, and at least one digit. Continuously reprompt the user until a valid password is entered. Display a message indicating whether the password is valid; if not, display the reason the password is not valid. Save the file as ValidatePassword. java

+1
Answers (1)
  1. 14 May, 09:55
    0
    import java. util. Scanner;

    public class ValidatePassword {

    public static void main (String[] args) {

    / / TODO Auto-generated method stub

    Scanner scanner = new Scanner (System. in);

    do {

    System. out. print ("/nEnter Password:");

    String password = "";

    password = scanner. nextLine ();

    int upperFound = 0, lowerFound = 0, digitFound = 0;

    for (char c : password. toCharArray ()) {

    if (Character. isUpperCase (c)) {

    upperFound++;

    } else if (Character. isLowerCase (c)) {

    lowerFound++;

    } else if (Character. isDigit (c)) {

    digitFound++;

    }

    }

    String errorMessage = "";

    if (upperFound < 2) {

    errorMessage + = "/n uppercase letters";

    }

    if (lowerFound < 2) {

    errorMessage + = "/n lowercase letters";

    }

    if (digitFound < 2) {

    errorMessage + = "/n digits";

    }

    / / System. out. println (errorMessage);

    if (errorMessage. length () > 1) {

    System. out

    . println ("The password did not have enough of the following: "

    + errorMessage);

    } else {

    System. out. println ("Valid password");

    break;

    }

    } while (true);

    }

    }

    output:

    Enter Password:23testkk

    The password did not have enough of the following:

    uppercase letters

    Enter Password:TESTabc12345

    Valid password
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write an application that prompts the user for a password that contains at least two uppercase letters, at least three lowercase letters, ...” in 📙 Engineering if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers