我的密码条件是,最少 8 个字符,最少 1 个特殊字符,最少 1 个数字
为此,我编写了一个简单的类来验证,但最终失败了。
非常感谢任何帮助。
public class PasswordVerifier {
private static final String SPECIAL_CHARACTERS = "(`~!@#$%^&*()_+=-][;'/.,\\<>?|:\"}{)";
public static void main(String... args) {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
String password = in.readLine();
if(!password.matches("^.*(?=.{8,})(?=.*[0-9])(?=.*[SPECIAL_CHARACTERS]).*$")){
System.out.println("Password does not satisfy compliant");
} else {
System.out.println("Yes.. gets through");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}