-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword Strength Visualizer.java
More file actions
33 lines (25 loc) · 992 Bytes
/
Password Strength Visualizer.java
File metadata and controls
33 lines (25 loc) · 992 Bytes
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
import java.util.Scanner;
public class PasswordStrengthVisualizer {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter password: ");
String pwd = sc.nextLine();
int score = 0;
if (pwd.length() >= 8) score++;
if (pwd.matches(".*[A-Z].*")) score++;
if (pwd.matches(".*[a-z].*")) score++;
if (pwd.matches(".*[0-9].*")) score++;
if (pwd.matches(".*[@#$%!^&*].*")) score++;
System.out.print("Strength: [");
for (int i = 0; i < score; i++) System.out.print("█");
for (int i = score; i < 5; i++) System.out.print("-");
System.out.print("] ");
switch (score) {
case 5 -> System.out.println("Very Strong 🔐");
case 4 -> System.out.println("Strong");
case 3 -> System.out.println("Medium");
default -> System.out.println("Weak ⚠️");
}
sc.close();
}
}