-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword.java
More file actions
55 lines (47 loc) · 1.67 KB
/
Copy pathPassword.java
File metadata and controls
55 lines (47 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
53
54
55
import java.util.*;
public class Password {
public static void main(String args[]) {
String password;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the password: ");
password = scanner.nextLine();
if(password.isEmpty()) {
System.out.println("Null");
}
else {
boolean isValid = isValidPassword(password);
if (isValid) {
System.out.println("Password is valid: " + password);
} else {
System.out.println("The Password is invalid!!!!! ");
}
}
}
public static boolean isValidPassword(String password) {
boolean isValid = true;
if(password.length()<8 || password.length()>10) {
System.out.println("Password length should be greater than 8 and less than 10");
isValid = false;
}
String upperCase = "(.*[A-Z].*)";
if(!password.matches(upperCase)) {
System.out.println("Password should contain Upper Case letters");
isValid = false;
}
String lowerCase = "(.*[a-z].*)";
if(!password.matches(lowerCase)) {
System.out.println("Password should contain Lower Case Letters");
}
String number = "(.*[0-9].*)";
if(!password.matches(number)) {
System.out.println("Password should contain numbers");
isValid = false;
}
String symbols = "(.*[@#$%].*$)";
if(password.matches(symbols)) {
System.out.println("Password should not contain symbols");
isValid = false;
}
return isValid;
}
}