-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpasswordValidator.java
More file actions
31 lines (24 loc) · 1.26 KB
/
passwordValidator.java
File metadata and controls
31 lines (24 loc) · 1.26 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
import java.util.Scanner;
class Main{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
System.out.print("Enter your password: ");
String password = input.nextLine();
passwordValidator(password);
}
public static void passwordValidator(String password){
boolean includeNumber = password.matches(".*\\d.*");
boolean includeLetterLowerCase = password.matches(".*[a-z].*");
boolean includeLetterUpperCase = password.matches(".*[A-Z].*");
boolean passwordIsLongerThanEightChar = password.length() >= 8;
boolean includeSpecialChar = !password.matches("[a-zA-Z0-9]*");
passwordChecker(includeLetterLowerCase, includeLetterUpperCase, includeNumber, passwordIsLongerThanEightChar, includeSpecialChar);
}
public static void passwordChecker(Boolean lowLetters, Boolean upperLetters, Boolean number, Boolean longer, Boolean specChar){
if(lowLetters && upperLetters && number && longer && specChar) print("Your password is strong");
else print( "include number: " + number + "\ninclude lower case letter: " + lowLetters + "\ninclude upper case letter: " + upperLetters + "\npassword longer than 8 letter: " + longer + "\ninclude specialChar: " + specChar);
}
public static void print(String text){
System.out.println(text);
}
}