Java密码强度正则表达式 – 必须包含大小写字母、数字、符号满足其中的3种

/**
 * @description: 密码强度校验
 * 1) 密码控制只能输入字母、数字、特殊符号(~!@#$%^&*()_+[]{}|\;:'",./<>?)
 * 2) 长度 8-30 位,必须包括大小写字母、数字、特殊符号中的3种
 * 3) 密码不能包含用户名信息
 * @author: wenbsu
 * @time: 2019/6/13 14:04
 **/

public class CheckPassword {
    //数字
    public static final String REG_NUMBER = ".*\\d+.*";
    //小写字母
    public static final String REG_UPPERCASE = ".*[A-Z]+.*";
    //大写字母
    public static final String REG_LOWERCASE = ".*[a-z]+.*";
    //特殊符号(~!@#$%^&*()_+|<>,.?/:;'[]{}\)
    public static final String REG_SYMBOL = ".*[~!@#$%^&*()_+|<>,.?/:;'\\[\\]{}\"]+.*";

    public static boolean checkPasswordRule(String password,String username){

        //密码为空及长度大于8位小于30位判断
        if (password == null || password.length() <8 || password.length()>30) return false;

        int i = 0;

        if (password.matches(CheckPassword.REG_NUMBER)) i++;
        if (password.matches(CheckPassword.REG_LOWERCASE))i++;
        if (password.matches(CheckPassword.REG_UPPERCASE)) i++;
        if (password.matches(CheckPassword.REG_SYMBOL)) i++;

        boolean contains = password.contains(username);

        if (i  < 3 || contains)  return false;

        return true;
    }

    public static void main(String[] args) {
        boolean flag = checkPasswordRule("wenb1su4232!A", "wenbsu");
        System.out.println(flag);
    }
}

 

  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值