package com.winsun.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CheckPwd {
    /**
     * 验证多媒体密码
     * @param new_password
     * @return
     */
    public static boolean checkPassword(String new_password) {
        if (new_password.length() < 8 || new_password.length() > 12) {
            //密码格式错误

            return false;
        } else {
            int passNumber = 0;

            Pattern pattern1 = Pattern.compile("(?=.*[-._/!@#$%^*]).{8,12}");

            Matcher m1 = pattern1.matcher(new_password);

            if (m1.matches()) {

                return false;
            }

            Pattern pattern2 = Pattern.compile("(?=.*\\d).{8,12}");

            Matcher m2 = pattern2.matcher(new_password);

            if (m2.matches()) {

                passNumber++;
            }

            Pattern pattern3 = Pattern.compile("(?=.*[a-z]).{8,12}");

            Matcher m3 = pattern3.matcher(new_password);

            if (m3.matches()) {

                passNumber++;
            }

            Pattern pattern4 = Pattern.compile("(?=.*[A-Z]).{8,12}");

            Matcher m4 = pattern4.matcher(new_password);

            if (m4.matches()) {

                passNumber++;
            }

            if (passNumber < 2) {
                //密码格式错误

                return false;
            }

            if (!new_password.matches("^[0-9a-zA-Z]{8,12}$")) {
                return false;

            }

            if (new_password.contains("&")) {
                return false;

            }

        }

        return true;
    }

}
