Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
密码等级:至少包含字母、大小写数字、字符中的两种
function passwordLevel(password) {
var Modes = 0;
for (i = 0; i < password.length; i++) {
Modes |= CharMode(password.charCodeAt(i));
}
return bitTotal(Modes);
//CharMode函数
function CharMode(iN) {
if (iN >= 48 && iN <= 57)//数字
return 1;
if (iN >= 65 && iN <= 90) //大写字母
return 2;
if ((iN >= 97 && iN <= 122) || (iN >= 65 && iN <= 90)) //大小写
return 4;
else
return 8; //特殊字符
}
//bitTotal函数
function bitTotal(num) {
modes = 0;
for (i = 0; i < 4; i++) {
if (num & 1) modes++;
num >>>= 1;
}
return modes;
}
}
// 使用语法:passwordLevel(string)
// 验证规则:数字、大写字母、小写字母、特殊字符
// 函数结果:返回密码中包含的规则数
// 运行例子:
// passwordLevel("123456") //返回1
// passwordLevel("Abc'123456") //返回4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.