|
@@ -2,66 +2,26 @@ |
|
@@ -2,66 +2,26 @@ |
2
|
* 计算密码复杂度
|
2
|
* 计算密码复杂度
|
3
|
*/
|
3
|
*/
|
4
|
|
4
|
|
5
|
-function gettype(str, i) {
|
|
|
6
|
- if (str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57) {
|
|
|
7
|
- return 1;
|
|
|
8
|
- } else if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) {
|
|
|
9
|
- return 2;
|
|
|
10
|
- } else if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
|
|
|
11
|
- return 3;
|
|
|
12
|
- }
|
|
|
13
|
-
|
|
|
14
|
- return 4;
|
|
|
15
|
-}
|
|
|
16
|
-
|
|
|
17
|
-function isregular(cur, pre, type) {
|
|
|
18
|
- var curCode = cur.charCodeAt(0);
|
|
|
19
|
- var preCode = pre.charCodeAt(0);
|
|
|
20
|
-
|
|
|
21
|
- if (curCode - preCode === 0) {
|
|
|
22
|
- return true;
|
|
|
23
|
- }
|
|
|
24
|
-
|
|
|
25
|
- if (type !== 4 && (curCode - preCode === 1 || curCode - preCode === -1)) {
|
|
|
26
|
- return true;
|
|
|
27
|
- }
|
|
|
28
|
-
|
|
|
29
|
- return false;
|
|
|
30
|
-}
|
|
|
31
|
-
|
|
|
32
|
-function getcomplex(curType, preType) {
|
|
|
33
|
- if (preType === 0 || curType === preType) {
|
|
|
34
|
- return 0;
|
|
|
35
|
- } else if (curType === 4 || preType === 4) {
|
|
|
36
|
- return 2;
|
5
|
+function computeComplex(password) {
|
|
|
6
|
+ var lengthS = 0;
|
|
|
7
|
+ var numS = 0;
|
|
|
8
|
+ var length = password.length;
|
|
|
9
|
+
|
|
|
10
|
+ if (length < 6) {
|
|
|
11
|
+ lengthS = 0;
|
|
|
12
|
+ } else if (length > 6 && length < 16) {
|
|
|
13
|
+ lengthS = 1;
|
37
|
} else {
|
14
|
} else {
|
38
|
- return 1;
|
15
|
+ lengthS = 2;
|
39
|
}
|
16
|
}
|
40
|
-}
|
|
|
41
|
-
|
|
|
42
|
-function computeComplex(password) {
|
|
|
43
|
- var complex = 0,
|
|
|
44
|
- length = password.length,
|
|
|
45
|
- pre = '',
|
|
|
46
|
- preType = 0,
|
|
|
47
|
- i = 0,
|
|
|
48
|
- cur,
|
|
|
49
|
- curType;
|
|
|
50
|
|
17
|
|
51
|
-
|
|
|
52
|
- for (i = 0; i < length; i++) {
|
|
|
53
|
- cur = password.charAt(i);
|
|
|
54
|
- curType = gettype(password, i);
|
|
|
55
|
-
|
|
|
56
|
- if (preType !== curType || !isregular(cur, pre, curType)) {
|
|
|
57
|
- complex += curType + getcomplex(curType, preType);
|
|
|
58
|
- }
|
|
|
59
|
-
|
|
|
60
|
- pre = cur;
|
|
|
61
|
- preType = curType;
|
18
|
+ if (/^[0-9]+$/.test(password) || /^[A-Za-z]+$/.test(password) || length === 0) {
|
|
|
19
|
+ numS = 0;
|
|
|
20
|
+ } else {
|
|
|
21
|
+ numS = 1;
|
62
|
}
|
22
|
}
|
63
|
|
23
|
|
64
|
- return complex;
|
24
|
+ return lengthS + numS;
|
65
|
}
|
25
|
}
|
66
|
|
26
|
|
67
|
module.exports = computeComplex; |
27
|
module.exports = computeComplex; |