-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasswordanalyzer.java
More file actions
52 lines (42 loc) · 1.61 KB
/
passwordanalyzer.java
File metadata and controls
52 lines (42 loc) · 1.61 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
import java.util.Scanner;
public class passwordanalyzer {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the password to analyze:");
String password = scanner.nextLine();
if (isStrongPassword(password)) {
System.out.println("Password is strong!");
} else {
System.out.println("Password is weak. Please improve it.");
}
}
private static boolean isStrongPassword(String password) {
// Minimum length requirement
if (password.length() < 8) {
System.out.println("Password must be at least 8 characters long.");
return false;
}
// Check for uppercase letters
if (!password.matches(".*[A-Z].*")) {
System.out.println("Password must contain at least one uppercase letter.");
return false;
}
// Check for lowercase letters
if (!password.matches(".*[a-z].*")) {
System.out.println("Password must contain at least one lowercase letter.");
return false;
}
// Check for digits
if (!password.matches(".*\\d.*")) {
System.out.println("Password must contain at least one digit.");
return false;
}
// Check for special characters
if (!password.matches(".*[!@#$%^&*()-+=].*")) {
System.out.println("Password must contain at least one special character.");
return false;
}
// If all criteria are met, the password is considered strong
return true;
}
}