前端密码校验8位以上,包含大写字母、小写字母、数字、特殊符号中的 3 种以上

1. 登录口令长度8位以上,包含大写字母、小写字母、数字、特殊符号中的 3 种以上

export const requirementRegexp = (value) => {
    const regexp = new RegExp(
        "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,20}$"
    );
    return regexp.test(value)
}

2. 排除 admin、root、password(不分字母大小写)

export const whitelist = (value) => {
    const str = value.toUpperCase();
    if (str.indexOf("ADMIN") >= 0 || str.indexOf("ROOT") >= 0
        || str.indexOf("PASSWORD") >= 0) {
        return true
    } else {
        return false
    }
}

3. 口令中连续数字超过3个(说明:比如123,234,345)

export const continuousStr = (str) => {
    var arr = str.split('');
    var flag = true;
    for (var i = 1; i < arr.length - 1; i++) {
        var firstIndex = arr[i - 1].charCodeAt();
        var secondIndex = arr[i].charCodeAt();
        var thirdIndex = arr[i + 1].charCodeAt();
        thirdIndex - secondIndex == 1;
        secondIndex - firstIndex == 1;
        if ((thirdIndex - secondIndex == 1) && (secondIndex - firstIndex == 1)) {
            flag = false;
        }
    }
    return flag;
}

4.口令中键盘顺序字符超过3个(横、竖排)(说明:比如ASD,ZXC,QAZ,ZSE,XDR等,就是键盘上三个能连成一条线的)。

export const _isKeyBoardContinuousChar = (str) => {
    var c1 = [
        ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+'],
        ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '{', '}', '|'],
        ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ':', '"'],
        ['z', 'x', 'c', 'v', 'b', 'n', 'm', '<', '>', '?']
    ];
    var c2 = [
        ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '='],
        ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\'],
        ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\''],
        ['z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/']
    ];
    str = str.split("");
    //获取坐标位置
    var y = [];
    var x = [];
    for (var c = 0; c < str.length; c++) {
        y[c] = 0;//当做~`键处理
        x[c] = -1;
        for (var i = 0; i < c1.length; i++) {
            for (var j = 0; j < c1[i].length; j++) {
                if (str[c] == c1[i][j]) {
                    y[c] = i;
                    x[c] = j;
                }
            }
        }
        if (x[c] != -1) continue;
        for (var i = 0; i < c2.length; i++) {
            for (var j = 0; j < c2[i].length; j++) {
                if (str[c] == c2[i][j]) {
                    y[c] = i;
                    x[c] = j;
                }
            }
        }
    }
    //匹配坐标连线
    for (var c = 1; c < str.length - 1; c++) {
        if (y[c - 1] == y[c] && y[c] == y[c + 1]) {
            if ((x[c - 1] + 1 == x[c] && x[c] + 1 == x[c + 1]) || (x[c + 1] + 1 == x[c] && x[c] + 1 == x[c - 1])) {
                return true;
            }
        } else if (x[c - 1] == x[c] && x[c] == x[c + 1]) {
            if ((y[c - 1] + 1 == y[c] && y[c] + 1 == y[c + 1]) || (y[c + 1] + 1 == y[c] && y[c] + 1 == y[c - 1])) {
                return true;
            }
        }
    }
    return false;
}

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嘴巴嘟嘟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值