[JAVA] password Regular expression Only 9 digits including letters + special characters + numbers



<%@ page import = "java.util.regex.Matcher"%>

<%@ page import = "java.util.regex.Pattern"%>


if(passwordParam.equals("changePwToNew")) {

boolean sameCharCheck = false;

String checkStr = "";

String returnMsg = "";

// Check the password format (more than 9 characters including English, special characters, and numbers)

Pattern passPattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*\\d)(?=.*[~!@#$%^*_+|<>?:{}])[A-Za-z\\d~!@#$%^*_+|<>?:{}]{9,}$");

Matcher passMatcher = passPattern.matcher(password);

// Check including 4 consecutive letters and numbers

int o = 0;

int d = 0;

int p = 0;

int n = 0;

int limit = 4;

    for (int i = 0; i < password.length(); i++) {

        char tmpVal = password.charAt(i);

        if (i > 0 && (p = o - tmpVal) > -2 && (n = p == d ? n + 1 : 0) > limit -3 ){

        sameCharCheck = true; // Has a continuous pattern

        }

        d = p;

        o = tmpVal;

    }

if(password != null && password.length() < 9){

returnStatus = "Password must be a combination of at least 9 characters, numbers, and special characters. !!";

}else if(!passMatcher.matches()){

returnStatus = "Password must be a combination of at least 9 characters, numbers, and special characters. !!";

}else if(sameCharCheck){

returnStatus = "Consecutive numbers and letters in the password cannot be changed. !!";

}else{

returnStatus = "changed success !!";

}

%>

<script type="text/javascript">

alert('<%=returnStatus%>');

location.href = 'retunr URL';

</script>

<%


😀

Thank you!!

고마워!!

Comments