-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString2.java
More file actions
59 lines (45 loc) · 1.67 KB
/
String2.java
File metadata and controls
59 lines (45 loc) · 1.67 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 String2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.nextLine();
System.out.println("Password Analysis:");
for (int i = 1; i <= n; i++) {
String password = scan.nextLine();
boolean hasUpper = false;
boolean hasLower = false;
boolean hasDigit = false;
boolean hasSpecial = false;
for (int j = 0; j < password.length(); j++) {
char ch = password.charAt(j);
if (Character.isUpperCase(ch))
hasUpper = true;
else if (Character.isLowerCase(ch))
hasLower = true;
else if (Character.isDigit(ch))
hasDigit = true;
else if ("!@$%^&".indexOf(ch) != -1)
hasSpecial = true;
}
String reason = "";
if (password.length() < 8)
reason += "Length < 8, ";
if (!hasUpper)
reason += "Missing upper, ";
if (!hasLower)
reason += "Missing lower, ";
if (!hasDigit)
reason += "Missing digit, ";
if (!hasSpecial)
reason += "Missing special, ";
if (reason.equals("")) {
System.out.println(i + ". " + password + " - Strong");
} else {
reason = reason.substring(0, reason.length() - 2);
System.out.println(i + ". " + password + " - Weak (" + reason + ")");
}
}
scan.close();
}
}