-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.js
105 lines (87 loc) · 2.21 KB
/
index.js
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var charsets = require('./lib/rules/contains').charsets;
var upperCase = charsets.upperCase;
var lowerCase = charsets.lowerCase;
var numbers = charsets.numbers;
var specialCharacters = charsets.specialCharacters;
var PasswordPolicy = require('./lib/policy');
var none = new PasswordPolicy({
length: { minLength: 1 }
});
var low = new PasswordPolicy({
length: { minLength: 6 }
});
var fair = new PasswordPolicy({
length: { minLength: 8 },
contains: {
expressions: [lowerCase, upperCase, numbers]
}
});
var good = new PasswordPolicy({
length: { minLength: 8 },
containsAtLeast: {
atLeast: 3,
expressions: [lowerCase, upperCase, numbers, specialCharacters]
}
});
var excellent = new PasswordPolicy({
length: { minLength: 10 },
containsAtLeast: {
atLeast: 3,
expressions: [lowerCase, upperCase, numbers, specialCharacters]
},
identicalChars: { max: 2 }
});
var policiesByName = {
none: none,
low: low,
fair: fair,
good: good,
excellent: excellent
};
/**
* Creates a password policy.
*
* @param {String} policyName Name of policy to use.
*/
module.exports = function (policyName) {
var policy = policiesByName[policyName] || policiesByName.none;
return {
/**
* Checks that a password meets this policy
*
* @method check
* @param {String} password
*/
check: function (password) {
return policy.check(password);
},
/**
* @method assert
* Asserts that a passord meets this policy else throws an exception.
*
* @param {String} password
*/
assert: function (password) {
return policy.assert(password);
},
missing: function (password) {
return policy.missing(password);
},
missingAsMarkdown: function (password) {
return policy.missingAsMarkdown(password);
},
explain: function () {
return policy.explain();
},
/**
* Friendly string representation of the policy
* @method toString
*/
toString: function () {
return policy.toString();
}
};
};
module.exports.PasswordPolicy = PasswordPolicy;
module.exports.charsets = charsets;
// module.exports.rulesToApply = rulesToApply;