繁体   English   中英

密码未检查Java中的长度条件

[英]Password not checking length condition in Java

我已经苦苦挣扎了4个小时,但是我输入密码的字符串没有检查长度条件。 我知道我在犯一些愚蠢的错误,但不幸的是我无法弄清楚。 最后,我决定向这里的专家询问,请对此提供帮助。

PS:我正在编写一个函数来验证密码,其长度为4到11个字符,包含一个大写字母,一个小写字母,一位数字和一个特殊字符。

public void validPassword(){
    String password;
    boolean con = true;

    Pattern[] passRegex = new Pattern[4];

    {
        passRegex[0] = Pattern.compile(".*[A-Z].*");
        passRegex[1] = Pattern.compile(".*[a-z].*");
        passRegex[2] = Pattern.compile(".*\\d.*");
        passRegex[3] = Pattern.compile("[A-Za-z0-9]*");
    }

    while(con){
        System.out.println("Enter Your Password Using Correct Format:");
        password = input.next();

            if(password.length() < 4 && password.length() > 11){
                System.out.println("Your Password Should Be 4 To 11 Characters Long");
            }
            if(!passRegex[0].matcher(password).matches()){
                System.out.println("Your Password Must Contain Atleast One UpperCase Letter");
                }
            if(!passRegex[1].matcher(password).matches()){
                System.out.println("Your Password Must Contain Atleast One LowerCase Letter");
                }
            if(!passRegex[2].matcher(password).matches()){
                System.out.println("Your Password Must Contain Atleast One Digit");
                }
            if(passRegex[3].matcher(password).matches()){
                System.out.println("Your Password Must Contain Atleast One Special Character");
                }
            else{
            System.out.println("Your Password Is Correct");
            con = false;
            }
    }
}

您需要或您的第一个条件不是

        if(password.length() < 4 || password.length() > 11){

        if(password.length() < 4 && password.length() > 11){

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM