Validate Password Strength

This program validates password strength using regex.

Problem Statement

Write a Java program to validate password with at least one uppercase, one lowercase, one digit, and one special character.

Source Code

1 public class RegexPasswordValidation {
2 public static void main(String[] args) {
3 System.out.println("Eduinq Regex Password Validation");
4 String password="Eduinq@123";
5 String regex="^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@#$%^&+=]).{8,}$";
6 if(password.matches(regex)) System.out.println("Strong password");
7 else System.out.println("Weak password");
8 }
9 }

Program Output

Eduinq Regex Password Validation
Strong password

Explanation

The regex uses lookahead groups to require at least one uppercase letter, one lowercase letter, one digit, and one special character, along with a minimum length of 8, together validating password strength.

Quick Links to Explore