-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrongPass.java
More file actions
60 lines (54 loc) · 1.25 KB
/
Copy pathStrongPass.java
File metadata and controls
60 lines (54 loc) · 1.25 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
53
54
55
56
57
58
59
60
import java.util.Scanner;
public class StrongPass
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your password: ");
String password = scanner.nextLine();
int missingCriteria = 0;
// Checking the length of the password
if (password.length() < 6)
{
missingCriteria += (6 - password.length());
}
boolean lowerCase = false;
boolean upperCase = false;
boolean digit = false;
boolean specialChar = false;
// Loop through each character of the password to check conditions
for (char ch : password.toCharArray())
{
if (Character.isLowerCase(ch))
{
lowerCase = true;
}
else if (Character.isUpperCase(ch))
{
upperCase = true;
}
else if (Character.isDigit(ch))
{
digit = true;
}
else if (!Character.isLetterOrDigit(ch))
{
specialChar = true;
}
}
// Checking for missing criteria
if (!lowerCase) missingCriteria++;
if (!upperCase) missingCriteria++;
if (!digit) missingCriteria++;
if (!specialChar) missingCriteria++;
// Showing Final output
if (missingCriteria == 0)
{
System.out.println("Your password is strong!");
}
else
{
System.out.println("Your password is weak. You need " + missingCriteria + " more condition to make it strong.");
}
}
}