-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassStrength.java
More file actions
34 lines (31 loc) · 1 KB
/
PassStrength.java
File metadata and controls
34 lines (31 loc) · 1 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
public class PassStrength {
public String strength(String password) {
PasswordGenerator pg = new PasswordGenerator();
int length = password.length();
boolean upper = false;
boolean lower = false;
boolean digit = false;
boolean symbol = false;
int score = 0;
for(int i=0; i<length; i++) {
char s = password.charAt(i);
if (pg.UPPER.indexOf(s) >= 0) upper = true;
if (pg.LOWER.indexOf(s) >= 0) lower = true;
if (pg.DIGIT.indexOf(s) >= 0) digit = true;
if (pg.SYMBOL.indexOf(s) >= 0) symbol = true;
}
if(length >= 8) score++;
if(length >= 12) score++;
if(upper) score++;
if(lower) score++;
if(digit) score++;
if(symbol) score++;
if(score < 3) {
return "Weak";
} else if(score == 3 || score == 4) {
return "Medium";
} else {
return "Strong";
}
}
}