Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class StringPasswordStrength {
- public static void main(String[] args) {
- Scanner reader = new Scanner(System.in);
- System.out.print("Enter password: ");
- String password = reader.nextLine();
- if (strongEnough(password) == true) {
- System.out.print("OK");
- } else {
- System.out.print("Not strong enough!");
- }
- reader.close();
- }
- private static boolean strongEnough(String a) {
- if (a.matches("^((?=.*[A-Z])(?=.*[a-z])(?=.*\\d)|(?=.*[a-z])(?=.*\\d)"
- + "(?=.*[^0-9A-Za-z])|(?=.*[A-Z])(?=.*\\d)(?=.*[^0-9A-Za-z])|(?=.*[A-Z])"
- + "(?=.*[a-z])(?=.*[^0-9A-Za-z])).{8,}$")) {
- return true;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement