-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordStrengthChecker.java
More file actions
59 lines (49 loc) · 1.69 KB
/
Copy pathPasswordStrengthChecker.java
File metadata and controls
59 lines (49 loc) · 1.69 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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();
boolean hasUpper = false;
boolean hasLower = false;
boolean hasDigit = false;
boolean hasSpecial = false;
for (int i = 0; i < password.length(); i++) {
char ch = password.charAt(i);
if (Character.isUpperCase(ch)) {
hasUpper = true;
} else if (Character.isLowerCase(ch)) {
hasLower = true;
} else if (Character.isDigit(ch)) {
hasDigit = true;
} else {
hasSpecial = true;
}
}
int score = 0;
if (password.length() >= 8)
score++;
if (hasUpper)
score++;
if (hasLower)
score++;
if (hasDigit)
score++;
if (hasSpecial)
score++;
System.out.println("\nPassword Analysis:");
System.out.println("Length (>=8): " + (password.length() >= 8));
System.out.println("Uppercase Letter: " + hasUpper);
System.out.println("Lowercase Letter: " + hasLower);
System.out.println("Number: " + hasDigit);
System.out.println("Special Character: " + hasSpecial);
if (score == 5) {
System.out.println("\nPassword Strength: Strong");
} else if (score >= 3) {
System.out.println("\nPassword Strength: Medium");
} else {
System.out.println("\nPassword Strength: Weak");
}
sc.close();
}
}