In: Computer Science
•Write a JAVA program to check a given password strength from a user's input.
•Create a method to check the number of characters. It must be more than 8.
•Create a method to check the password to have at least one uppercase letter.
•Create a method to check the password to have at least one lowercase letter.
•Create a method to check the password to have at least one digit.
•Create a method to check the password to have at least one special character (!, 2, #, %, &, *, (, ), etc.)
•Create a method called isValid to check if the password is valid.
import java.util.Scanner;
public class PasswordValidator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a password: ");
String s = input.nextLine();
if (isValid(s)) {
System.out.println("Valid Password");
} else {
System.out.println("Invalid Password");
}
}
public static boolean isValid(String pwd) {
return checkCharCount(pwd) && checkForDigit(pwd) && checkForSpecial(pwd) && checkForLetter(pwd);
}
// checks if password has 8 characters
public static boolean checkCharCount(String pwd) {
return pwd.length() >= 8;
}
// checks if password has letter
public static boolean checkForLetter(String pwd) {
for (int i = 0; i < pwd.length(); i++)
if (Character.isLetter(pwd.charAt(i)))
return true;
return false;
}
// checks if password contains digit
public static boolean checkForDigit(String pwd) {
for (int i = 0; i < pwd.length(); i++)
if (Character.isDigit(pwd.charAt(i)))
return true;
return false;
}
// checks if password has special char
public static boolean checkForSpecial(String pwd) {
String spl = "!@#$%^&*()";
for (int i = 0; i < pwd.length(); i++)
if (spl.contains(pwd.charAt(i) + ""))
return true;
return false;
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME