forked from dimpeshpanwar/Java-Advance-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword_Strength_Checker.java
More file actions
44 lines (37 loc) · 1.64 KB
/
Password_Strength_Checker.java
File metadata and controls
44 lines (37 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.Scanner;
public class PasswordStrengthChecker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your password: ");
String password = sc.nextLine();
int length = password.length();
boolean hasUpper = false;
boolean hasLower = false;
boolean hasDigit = false;
boolean hasSpecial = false;
for (char ch : password.toCharArray()) {
if (Character.isUpperCase(ch))
hasUpper = true;
else if (Character.isLowerCase(ch))
hasLower = true;
else if (Character.isDigit(ch))
hasDigit = true;
else if (!Character.isLetterOrDigit(ch))
hasSpecial = true;
}
System.out.println("\nPassword Analysis:");
System.out.println("------------------");
System.out.println("Length: " + length);
System.out.println("Contains Uppercase: " + (hasUpper ? "Yes" : "No"));
System.out.println("Contains Lowercase: " + (hasLower ? "Yes" : "No"));
System.out.println("Contains Digit: " + (hasDigit ? "Yes" : "No"));
System.out.println("Contains Special Character: " + (hasSpecial ? "Yes" : "No"));
if (length >= 8 && hasUpper && hasLower && hasDigit && hasSpecial)
System.out.println("\n✅ Password Strength: STRONG");
else if (length >= 6 && ((hasUpper && hasLower) || hasDigit))
System.out.println("\n⚠️ Password Strength: MODERATE");
else
System.out.println("\n❌ Password Strength: WEAK");
sc.close();
}
}