Authored by htoooth

fix password strength

... ... @@ -2,66 +2,26 @@
* 计算密码复杂度
*/
function gettype(str, i) {
if (str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57) {
return 1;
} else if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) {
return 2;
} else if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
return 3;
}
return 4;
}
function isregular(cur, pre, type) {
var curCode = cur.charCodeAt(0);
var preCode = pre.charCodeAt(0);
if (curCode - preCode === 0) {
return true;
}
if (type !== 4 && (curCode - preCode === 1 || curCode - preCode === -1)) {
return true;
}
return false;
}
function getcomplex(curType, preType) {
if (preType === 0 || curType === preType) {
return 0;
} else if (curType === 4 || preType === 4) {
return 2;
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 {
return 1;
lengthS = 2;
}
}
function computeComplex(password) {
var complex = 0,
length = password.length,
pre = '',
preType = 0,
i = 0,
cur,
curType;
for (i = 0; i < length; i++) {
cur = password.charAt(i);
curType = gettype(password, i);
if (preType !== curType || !isregular(cur, pre, curType)) {
complex += curType + getcomplex(curType, preType);
}
pre = cur;
preType = curType;
if (/^[0-9]+$/.test(password) || /^[A-Za-z]+$/.test(password) || length === 0) {
numS = 0;
} else {
numS = 1;
}
return complex;
return lengthS + numS;
}
module.exports = computeComplex;
... ...
... ... @@ -332,19 +332,8 @@ function validatePassword() {
// 密码强度验证
function validatePasswordComplexLocal($obj) {
var pwd = $obj.val(),
pwdStrength = computeComplex(pwd),
level = 0;
if (pwdStrength === 0) {
level = 0;
} else if (pwdStrength <= 10) {
level = 1;
} else if (pwdStrength <= 20) {
level = 2;
} else {
level = 3;
}
level = computeComplex(pwd);
console.log(level);
switch (level) {
case 0:
$pwdParent.removeClass('red yellow green');
... ... @@ -483,7 +472,7 @@ exports.init = function() {
});
// 验证密码输入
$passwordInput.on('keyup blur', function() {
$passwordInput.on('keyup', function() {
var $this = $(this);
validatePassword().always(function() {
... ...