pwd-strength.js
496 Bytes
/*
* 计算密码复杂度
*/
function computeComplex(password) {
var lengthS = 0;
var numS = 0;
var length = password.length;
if (length < 6) {
lengthS = 0;
} else if (length > 6 && length < 16) {
lengthS = 1;
} else {
lengthS = 2;
}
if (/^[0-9]+$/.test(password) || /^[A-Za-z]+$/.test(password) || length === 0) {
numS = 0;
} else {
numS = 1;
}
return lengthS + numS;
}
module.exports = computeComplex;