Java判断密码强度工具类

/**
 * 
 */
package com.ssm.student.handlers;

/**
 * @className CheckPassword
 * @deprecated {描述这个类}
 * @author Administrator
 * @date 2017年11月8日
 */
public class CheckPassword {

    /**
     * 密码强度
     * 
     * @return Z = 字母 S = 数字 T = 特殊字符
     */

/*  一、假定密码字符数范围6-16,除英文数字和字母外的字符都视为特殊字符:
    弱:^[0-9A-Za-z]{6,16}$
    中:^(?=.{6,16})[0-9A-Za-z]*[^0-9A-Za-z][0-9A-Za-z]*$
    强:^(?=.{6,16})([0-9A-Za-z]*[^0-9A-Za-z][0-9A-Za-z]*){2,}$
    二、假定密码字符数范围6-16,密码字符允许范围为ASCII码表字符:
    弱:^[0-9A-Za-z]{6,16}$
    中:^(?=.{6,16})[0-9A-Za-z]*[\x00-\x2f\x3A-\x40\x5B-\xFF][0-9A-Za-z]*$
    强:^(?=.{6,16})([0-9A-Za-z]*[\x00-\x2F\x3A-\x40\x5B-\xFF][0-9A-Za-z]*){2,}$*/
    public static String checkPassword(String passwordStr) {
        String regexZ = "\\d*";
        String regexS = "[a-zA-Z]+";
        String regexT = "\\W+$";
        String regexZT = "\\D*";
        String regexST = "[\\d\\W]*";
        String regexZS = "\\w*";
        String regexZST = "[\\w\\W]*";

        if (passwordStr.matches(regexZ)) {
            return "弱";
        }
        if (passwordStr.matches(regexS)) {
            return "弱";
        }
        if (passwordStr.matches(regexT)) {
            return "弱";
        }
        if (passwordStr.matches(regexZT)) {
            return "中";
        }
        if (passwordStr.matches(regexST)) {
            return "中";
        }
        if (passwordStr.matches(regexZS)) {
            return "中";
        }
        if (passwordStr.matches(regexZST)) {
            return "强";
        }
        return passwordStr;

    }
}

你可能感兴趣的:(工具类,java,密码)