-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordChecker.java
More file actions
52 lines (42 loc) · 1.67 KB
/
PasswordChecker.java
File metadata and controls
52 lines (42 loc) · 1.67 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.sarvesh.javabasics;
import java.util.Scanner;
public class PasswordChecker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("""
┏━┓┏━┓┏━┓┏━┓╻ ╻┏━┓┏━┓╺┳┓ ┏━╸╻ ╻┏━╸┏━╸╻┏ ┏━╸┏━┓
┣━┛┣━┫┗━┓┗━┓┃╻┃┃ ┃┣┳┛ ┃┃ ┃ ┣━┫┣╸ ┃ ┣┻┓┣╸ ┣┳┛
╹ ╹ ╹┗━┛┗━┛┗┻┛┗━┛╹┗╸╺┻┛ ┗━╸╹ ╹┗━╸┗━╸╹ ╹┗━╸╹┗╸
""");
System.out.print("Enter a Password: ");
String password = sc.nextLine();
boolean hasUppercase = false;
boolean hasLowercase = false;
boolean hasDigits = false;
boolean hasSpecial = false;
for (int i = 0; i < password.length(); i++) {
char ch = password.charAt(i);
if (Character.isUpperCase(ch))
hasUppercase = true;
else if (Character.isLowerCase(ch))
hasLowercase = true;
else if (Character.isDigit(ch))
hasDigits = true;
else
hasSpecial = true;
}
int score = 0;
if (password.length() >= 8) score++;
if (hasUppercase) score++;
if (hasLowercase) score++;
if (hasDigits) score++;
if (hasSpecial) score++;
if (score <= 2)
System.out.println("Weak Password");
else if (score <= 4)
System.out.println("Medium Password");
else
System.out.println("Strong Password");
sc.close();
}
}