Hello everyone, Here I have attached simple program about Password Strength Checker Java Program Example. using Regular Expression this will give idea about password field implementation in your project. The program has been tested and output is shared in the same post.

PasswordStrengthChecker.java

package com.javatraineronline;
import java.util.Scanner;
public class PasswordStrengthChecker {
private static int checkPasswordStrength(String password) {
int passwordPercentageStrength = 0;
String[] passwordRegularExp = { // Your more password criteria goes here....
".*[a-z]+.*", // lower case
".*[A-Z]+.*", // upper case
".*[\\d]+.*", // digits
".*[@#$%]+.*" // symbols
};
if (password.matches(passwordRegularExp[0])) {
passwordPercentageStrength += 25;
}
if (password.matches(passwordRegularExp[1])) {
passwordPercentageStrength += 25;
}
if (password.matches(passwordRegularExp[2])) {
passwordPercentageStrength += 25;
}
if (password.matches(passwordRegularExp[3])) {
passwordPercentageStrength += 25;
}
return passwordPercentageStrength;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(true) {
System.out.println("Enter the password: ");
String password = scanner.nextLine();
int percent = checkPasswordStrength(password);
if(percent == 25) {
System.out.println("Password strength is Bad..");
System.out.println("Please try again....");
System.out.println();
} else if(percent == 50) {
System.out.println("Password strength is Ok");
System.out.println("Please try again....");
System.out.println();
} else if(percent == 75) {
System.out.println("Password strength is Good");
System.out.println("Stil you want to better up??? (Y/N)");
String decision = scanner.nextLine();
if("Y".equalsIgnoreCase(decision)) {
percent = checkPasswordStrength(password);
} else {
break;
}
} else if(percent == 100) {
System.out.println("Password strength is Excellent");
break;
}
}
}
}

Output

————————
Enter the password:
java
Password strength is Bad..
Please try again….

Enter the password:
Java
Password strength is Ok
Please try again….

Enter the password:
Java123
Password strength is Good
Stil you want to better up??? (Y/N)
Y
Enter the password:
Java@123
Password strength is Excellent

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *