Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming Implement a program that reads in a user password and verifies

ID: 3774545 • Letter: J

Question

Java Programming

Implement a program that reads in a user password and verifies it meets the following criteria:

- At least 8 characters long

- Contains at lease 1 lower letter character

- Contains at least 1 upper letter character

- Contains at least 1 numeric digit

- Contains at least 1 special character from the set !@#$%^&*

- Does not contain the word "and" or the word "the"

- Promts the user for a password, including the requirements above in your output.

- Output a string that states valid or invalid. If invalid, state which rules from the list above have been met, and prompt the user to enter another password.

Utilize the following functionality:

- indexOf

- Looping structure

- charAT()

- isDigit()

- isUpperCase()

- isLowerCase()

Sample Output:

Password Verifier

Enter a password that meets the following rules:
<list rules from above>
Password1

Invalid
Missing a special character

-----------------------------------------------------------------

Password Verifier

Enter a password that meets the following rules:
<list rules from above>
Panda123$

Invalid
Contains the string “and”

-----------------------------------------------------------------

Password Verifier

Enter a password that meets the following rules:
<list rules from above>
Hi

Invalid
Must be at least 8 characters long
Must contain a numeric digit
Must contain a special character

-----------------------------------------------------------------

Password Verifier

Enter a password that meets the following rules:
<list rules from above>
Pa$$word1

Valid

Explanation / Answer

PasswordChecker.java

import java.util.*;
class PasswordChecker
{
public static boolean isValid(String password)
{
String symbol = "!@#$%^&*";
int upperCaseCount = 0;
int lowerCaseCount = 0;
int digitCount = 0;
boolean hasSymbol = false;
if(password.length() >= 8) {//Checks for length.
int i = 0;
while( i < password.length()) //For each character.
{
char c = password.charAt(i);
if(Character.isUpperCase(c) ) //If uppercase, increment counter.
upperCaseCount++;
if(Character.isLowerCase(c)) //If lowercase, increment counter.
lowerCaseCount++;
if(Character.isDigit(c)) //If digit, increment counter.
digitCount++;
if(symbol.indexOf(c) != -1 && hasSymbol == false) //If has symbol, mark flag.
hasSymbol = true;
i++;
}
} else {
System.out.println("Invalid password. Password length should be no less than 8.");
return false;
}
if(upperCaseCount < 1) {
System.out.println("Invalid password. Password should contain minimum 1 uppercase letter.");
return false;
}
if(lowerCaseCount < 1) {
System.out.println("Invalid password. Password should contain minimum 1 lowercase letter.");
return false;
}
if(digitCount < 1) {
System.out.println("Invalid password. Password should contain minimum 1 digits.");
return false;
}
if(!hasSymbol) {
System.out.println("Invalid password. Password should contain atleast one special characters from ! @ # $ % ^ & * ");
return false;
}
return true;
}
public static void main(String args[]){
   Scanner scan = new Scanner(System.in);
   System.out.print("Ennter the password: ");
   String pass = scan.next();
   while(!isValid(pass)){
       System.out.print("Ennter the password: ");
   pass = scan.next();
          
   }
   System.out.println("Given password is valid");
}
}

Output:

Ennter the password: pass
Invalid password. Password length should be no less than 8.
Ennter the password: password
Invalid password. Password should contain minimum 1 uppercase letter.
Ennter the password: Password
Invalid password. Password should contain minimum 1 digits.
Ennter the password: Password12
Invalid password. Password should contain atleast one special characters from ! @ # $ % ^ & *
Ennter the password: Password12!@
Given password is valid

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote