-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordStrengthChecker.java
More file actions
43 lines (34 loc) · 1.13 KB
/
Copy pathPasswordStrengthChecker.java
File metadata and controls
43 lines (34 loc) · 1.13 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
import java.util.Scanner;
public class PasswordStrengthChecker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter password: ");
String password = sc.nextLine();
int score = 0;
boolean hasUpper = false;
boolean hasLower = false;
boolean hasDigit = false;
boolean hasSpecial = false;
if (password.length() >= 8) {
score++;
}
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 hasSpecial = true;
}
if (hasUpper) score++;
if (hasLower) score++;
if (hasDigit) score++;
if (hasSpecial) score++;
if (score == 5) {
System.out.println("Strong Password");
} else if (score >= 3) {
System.out.println("Medium Password");
} else {
System.out.println("Weak Password");
}
sc.close();
}
}