-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordChecker.js
More file actions
84 lines (74 loc) · 2.69 KB
/
Copy pathPasswordChecker.js
File metadata and controls
84 lines (74 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var PasswordContext = (function () {
function PasswordContext() {
}
return PasswordContext;
})();
var PasswordChekcer = (function () {
function PasswordChekcer() {
}
PasswordChekcer.contains = function (arr, value) {
return arr.indexOf(value) !== -1;
};
PasswordChekcer.CheckPassword = function (password, additionalValues, context) {
var junk = [], i, numberOfRepeats = 0, maxrepeat, additionalValue;
if (password.length < 4) {
return PasswordChekcer.ReturnValues.WayTooShort;
}
if (password.length < PasswordChekcer.minlength) {
return PasswordChekcer.ReturnValues.TooShort;
}
if (!password.replace(/[ \t]/g, "").length) {
return PasswordChekcer.ReturnValues.AllWhitespace;
}
for (i = 0; i < password.length; i++) {
if (!PasswordChekcer.contains(junk, password[i])) {
junk.push(password[i]);
}
}
if (junk.length < PasswordChekcer.mindiff) {
return PasswordChekcer.ReturnValues.TooLittleVariety;
}
for (i = 0; i < password.length - 1; i++) {
if (Math.abs((password.charCodeAt(i + 1) - (password.charCodeAt(i)))) === 1) {
numberOfRepeats++;
}
}
maxrepeat = Math.floor(3 + (0.09 * password.length));
if (numberOfRepeats > maxrepeat) {
return PasswordChekcer.ReturnValues.TooSystematic;
}
if (additionalValues) {
for (i = 0; i < additionalValues.length; i++) {
additionalValue = additionalValues[i];
if (password.search(additionalValue) !== -1) {
if (context) {
context.matchedValue = additionalValue;
}
return PasswordChekcer.ReturnValues.BasedOnValue;
}
additionalValue = additionalValue.split('').reverse().join('');
if (password.search(additionalValue) !== -1) {
if (context) {
context.matchedValue = additionalValues[i];
}
return PasswordChekcer.ReturnValues.BasedOnReversedValue;
}
}
}
return PasswordChekcer.ReturnValues.OK;
};
PasswordChekcer.ReturnValues = {
OK: 0,
WayTooShort: 1,
TooShort: 2,
AllWhitespace: 3,
TooLittleVariety: 4,
TooSystematic: 5,
BasedOnValue: 6,
BasedOnReversedValue: 7
};
PasswordChekcer.minlength = 6;
PasswordChekcer.mindiff = 5;
return PasswordChekcer;
})();
//# sourceMappingURL=PasswordChecker.js.map