File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments