Skip to content

Commit bc38d57

Browse files
Implement password strength visualizer
1 parent 36d5d9e commit bc38d57

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Password Strength Visualizer.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.Scanner;
2+
3+
public class PasswordStrengthVisualizer {
4+
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
8+
System.out.print("Enter password: ");
9+
String pwd = sc.nextLine();
10+
11+
int score = 0;
12+
13+
if (pwd.length() >= 8) score++;
14+
if (pwd.matches(".*[A-Z].*")) score++;
15+
if (pwd.matches(".*[a-z].*")) score++;
16+
if (pwd.matches(".*[0-9].*")) score++;
17+
if (pwd.matches(".*[@#$%!^&*].*")) score++;
18+
19+
System.out.print("Strength: [");
20+
for (int i = 0; i < score; i++) System.out.print("█");
21+
for (int i = score; i < 5; i++) System.out.print("-");
22+
System.out.print("] ");
23+
24+
switch (score) {
25+
case 5 -> System.out.println("Very Strong 🔐");
26+
case 4 -> System.out.println("Strong");
27+
case 3 -> System.out.println("Medium");
28+
default -> System.out.println("Weak ⚠️");
29+
}
30+
31+
sc.close();
32+
}
33+
}

0 commit comments

Comments
 (0)