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;
}