Ask Question
1 February, 08:10

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

+5
Answers (1)
  1. 1 February, 08:13
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers