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

Regex checks for uppercase, lowercase, digit, special character. - Minimum length enforced. - Together validates password strength. Conclusion: Shows how to validate password strength using regex.

Quick Links to Explore