Skip to content

Commit 8a03270

Browse files
Password Strength Checker
1 parent 057da43 commit 8a03270

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
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+
}
46+
}
47+
}

0 commit comments

Comments
 (0)