I've just created this class for a password validation
/*
* ^ Start anchor
* (?=.*[A-Z].*[A-Z]) Ensure string has two uppercase letters.
* (?=.*[!@#$&*]) Ensure string has one special case letter.
* (?=.*[0-9].*[0-9]) Ensure string has two digits.
* (?=.*[a-z].*[a-z].*[a-z]) Ensure string has three lowercase letters.
* .{8} Ensure string is of length 8.
* $ End anchor.
*/
public class PasswordUtils {
private static final String PWD_REGEX = "^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z])";
/**
* Non instantiable.
*/
private PasswordUtils() {
throw new AssertionError("Non instantiable");
}
public static boolean match (String pwd1, String pwd2) {
return StringUtils.equals(pwd1, pwd2);
}
public static boolean isStrong(String password){
return password.matches(PWD_REGEX);
}
}
Then this Junit, but it seems that the pwd does not match the requirements of the regular expression
private final String PWD6 = "Pi89pR&s";
@Test
public void testStrong () {
assertTrue(PasswordUtils.isStrong(PWD6));
}