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