-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword_Strength_Checker.java
More file actions
33 lines (27 loc) · 1.18 KB
/
Password_Strength_Checker.java
File metadata and controls
33 lines (27 loc) · 1.18 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
import java.util.Scanner;
public class Password_Strength_Checker {
public static String checkStrength(String password) {
int length = password.length();
boolean hasUpper = false, hasLower = false, hasDigit = false, 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 hasSpecial = true;
}
if (length >= 12 && hasUpper && hasLower && hasDigit && hasSpecial) {
return "Strong password";
} else if (length >= 8 && ((hasUpper && hasLower) || (hasDigit && hasSpecial))) {
return "Moderate password";
} else {
return "Weak password";
}
]
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a password to check its strength: ");
String password = scanner.nextLine();
System.out.println("Password Strength: " + checkStrength(password));
scanner.close();
}
}