即使我给出的密码是真的,if 语句仍然给我错误的条件[关闭]
温馨提示:
本文最后更新于 2024年04月12日,已超过 37 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我。
public static boolean checkPasswordComplexity(){
String Hold_Password = Password_Acceptor();
Pattern Password_complex_checker = Pattern.compile("[a-zA-Z0-9]*");//remember to code attribute this
Pattern Password_Capital_letters = Pattern.compile("[A-Z]");//check capital
Pattern Password_number_checker = Pattern.compile("[0-9]");//check numbers
Matcher Pass_complex_check_matcher = Password_complex_checker.matcher(Hold_Password);//check special character
Matcher Password_Capital_letter_checker = Password_Capital_letters.matcher(Hold_Password);//check capital letters
Matcher Password_number_checker_2 = Password_number_checker.matcher(Hold_Password);//checks for number
if(Hold_Password.length()>=8 && !Pass_complex_check_matcher.matches() && (Password_Capital_letter_checker.matches()) && (Password_number_checker_2.matches())){
System.out.println("Password successfullly captured");
return true;
}
// checks these 4 conditions and returns true or false, these ae the ones giving me problems
else{
System.out.println("Password is not correctly formatted, please "
+ "ensure that the password contains atleast 8 characters, "
+ "a capital letter, a number and a special character ");
return false;
}
}
I ran my code and expected it to return the true condition since the password that I gave this function was true, yet no matter what I do it returns false I remmoved the last two and statements as a test to see if they where the problem and to my suprise the last 2 and statements where the ones causing me problems, and only then did it return true but that isnt a solution please help.
正文到此结束
- 本文标签: 家庭宠物
- 本文链接: https://www.coder6.net/article/2186
- 版权声明: 本文由蚂蚁原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权