Skip to content

Commit 856509a

Browse files
Password Strength Checker
1 parent 8a03270 commit 856509a

File tree

1 file changed

+42
-44
lines changed

1 file changed

+42
-44
lines changed
Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
11
public class PasswordStrength {
2-
public static void main(final String ar[]) {
3-
String password = AbraKadabra1287832FQENi;
4-
5-
boolean hasLetter = false;
6-
boolean hasDigit = false;
7-
boolean hasUpperCase = false;
8-
boolean hasLowerCase = false;
9-
10-
if (password.length() >= 8) {
11-
for (int i = 0; i < password.length(); i++) {
12-
char x = password.charAt(i);
13-
if (Character.isLetter(x)) {
14-
if(Character.isUpperCase(x)){
15-
16-
hasUpperCase = true;
17-
18-
}else if(Character.isLowerCase(x)){
19-
20-
hasLowerCase = true;
21-
}
22-
23-
hasLetter = true;
24-
}
25-
26-
else if (Character.isDigit(x)) {
27-
28-
hasDigit = true;
29-
}
30-
31-
// no need to check further, break the loop
32-
if(hasLetter && hasDigit && hasUpperCase && hasLowerCase){
33-
34-
break;
35-
}
36-
37-
}
38-
if (hasLetter && hasDigit && hasUpperCase && hasLowerCase) {
39-
System.out.println("STRONG");
40-
} else {
41-
System.out.println("NOT STRONG");
42-
}
43-
} else {
44-
System.out.println("HAVE AT LEAST 8 CHARACTERS");
45-
}
2+
public static void main(final String ar[]) {
3+
String password = AbraKadabra1287832FQENi;
4+
5+
boolean hasLetter = false;
6+
boolean hasDigit = false;
7+
boolean hasUpperCase = false;
8+
boolean hasLowerCase = false;
9+
10+
if (password.length() >= 8) {
11+
for (int i = 0; i < password.length(); i++) {
12+
char x = password.charAt(i);
13+
if (Character.isLetter(x)) {
14+
if (Character.isUpperCase(x)) {
15+
16+
hasUpperCase = true;
17+
18+
} else if (Character.isLowerCase(x)) {
19+
20+
hasLowerCase = true;
21+
}
22+
23+
hasLetter = true;
24+
} else if (Character.isDigit(x)) {
25+
26+
hasDigit = true;
4627
}
28+
29+
// no need to check further, break the loop
30+
if (hasLetter && hasDigit && hasUpperCase && hasLowerCase) {
31+
32+
break;
33+
}
34+
35+
}
36+
if (hasLetter && hasDigit && hasUpperCase && hasLowerCase) {
37+
System.out.println("STRONG");
38+
} else {
39+
System.out.println("NOT STRONG");
40+
}
41+
} else {
42+
System.out.println("HAVE AT LEAST 8 CHARACTERS");
43+
}
44+
}
4745
}

0 commit comments

Comments
 (0)