强密码校验

强密码规则: 必须包含大小写字母和特殊字符, 长度为8至30位

JS版本强密码规则校验

var regex= /^(?![A-z0-9]+$)(?=.[^%&',;=?$\x22])(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{8,20}$/;
console.log(regex.test("Qq123456*"));

Java版本强密码规则校验

package com.util;

/**
 * @Description 密码强度校验
 *  * 1) 密码控制只能输入字母、数字、特殊符号(~!@#$%^&*()_+[]{}|\;:'",./<>?)
 *  * 2) 长度 8-30 位,必须包括大小写字母、数字、特殊符号中的4种
 *  * 3) 密码不能用户名信息相同
 * @Author Yzx
 * @Date 2021-4-28 15:27
 * @Version V1.0.0
 */
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.equals(username);
		
		//此处可以判定包含几种强密码为4
        if (i  < 4 || contains)  return false;

        return true;
    }

    public static void main(String[] args) {
        System.out.println(checkPasswordRule("1234@Root", ""));
    }

}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值