Java Password Strength Checker – Shield Your Accounts

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

In this project, we examine the creation of a Java-based password strength checker. We intend to give consumers a useful tool to evaluate the security level of their passwords by developing a programme that assesses the strength of passwords based on particular criteria.

About Java Password Strength Checker:

We have considered the following criteria to assess a given password:

1. Length: A strong password must consist of at least 12 characters.
2. Complexity: A password is said to be strong if it has at least

  • one Uppercase character,
  • one Lowercase character,
  • a Digit and
  • a Special character or Symbol.

Prerequisites for Java Password Strength Checker

  • IDE Used: Intellij
  • Java 1.8 or above must be installed.

Download Java Password Strength Checker Project

Please download the source code of Java Password Strength Checker Project from the following link: Java Password Strength Checker Project Code

Steps to Create Java Password Strength Checker:

1. Import Packages
2. The main() method
3. Implement the passwordStrength() method

  • Evaluate password strength
  • Assign Strength levels
  • Return strength result

4. Test the Password Strength Checker

1. Import Packages:

In this step, we will import the java.util package to access the Scanner class to take input from the user.

import java.util.Scanner;

2. The main() method:

The main() method is used to prompt the user for the password and store it in the password variable. Also assign the result of ‘passwordStrength’ to the string variable ‘strength’ and print the strength of the password.

public static void main(String[] args) {
   System.out.println("\n\t\tDataFlair's Password Strength Checker \n");
   System.out.println("Enter the password: \n");
   Scanner sc = new Scanner(System.in);
   String password = sc.nextLine();
   String strength = passwordStrength(password);
   System.out.println("Strength: " + strength);
}

3. Implement the passwordStrength() method:

  • Create a method named ‘passwordStrength’ that takes a password as input and returns a string representing the strength of the password.
  • Initialize the following boolean variables: ‘containsLowerChar’, ‘containsUpperChar’, ‘containsDigit’, ‘containsSpecialChar’, and ‘minLength’.
public static String passwordStrength(String pass){
   boolean containsLowerChar= false, containsUpperChar = false;
   boolean containsDigit = false, containsSpecialChar = false,    minLength = false;
   String special_chars = "!(){}[]:;<>?,@#$%^&*+=_-~`|./'";
   String strength;
   char[] ch= pass.toCharArray();
  • Evaluate the password strength by iterating over each character of the password and checking the following conditions:

1. If the character is a lowercase letter, set ‘containsLowerChar’ to true.
2. If the character is an uppercase letter, set ‘containsUpperChar’ to true.
3. If the character is a digit, set ‘containsDigit’ to true.
4. If the character is a special character, set ‘containsSpecialChar’ to true.

  • Also, check that the minimum length of the password is 12. If it is, then set ‘minLength’ to true.
for(int i=0; i<pass.length(); i++){
   if(Character.isLowerCase(ch[i])){
       containsLowerChar = true;
   }
   if(Character.isUpperCase(ch[i])){
       containsUpperChar = true;
   }
   if(Character.isDigit(ch[i])){
       containsDigit = true;
   }
   if(special_chars.contains(String.valueOf(ch[i]))){
       containsSpecialChar = true;
   }
}
if (pass.length() >= 12){
   minLength = true;
}
  • Assign strength levels based on the password evaluation criteria to the ‘strength’ variable and return the strength result.
if(minLength && containsDigit && containsUpperChar && containsSpecialChar && containsLowerChar){
   strength = "Strong";
} else if (minLength && ((containsUpperChar && containsLowerChar) || containsDigit || containsSpecialChar )) {
   strength = "Medium";
}else{
   strength = "Weak";
}
return strength;

4. Test the Password Strength Checker:

Run the program and enter different passwords to test the strength checker.

Weak Password Strength

java password strength checker output

Medium Password Strength

medium password strength

Strong Password Strength

strong password strength

Conclusion

The Password Strength Checker program emphasizes the value of using a variety of character types, such as capital letters, lowercase letters, numerals, and special characters, to strengthen passwords. It encourages users to establish longer and more secure passwords by requiring a minimum of 12 characters. The Password Strength Checker programme encourages responsible password usage and emphasizes the importance of strong passwords in protecting sensitive data.

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

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