auth0-password-policies 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/index.js +9 -8
- package/package.json +1 -1
- package/test/test.js +7 -10
package/README.md
CHANGED
|
@@ -36,8 +36,8 @@ const { createRulesFromOptions } = require('auth0-password-policies');
|
|
|
36
36
|
|
|
37
37
|
const passwordOptions = {
|
|
38
38
|
character_types: ["uppercase","lowercase","number","special"],
|
|
39
|
-
"
|
|
40
|
-
identical_characters: "
|
|
39
|
+
character_type_rule: "three_of_four",
|
|
40
|
+
identical_characters: "block"
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
const rules = createRulesFromOptions(passwordOptions);
|
package/index.js
CHANGED
|
@@ -46,8 +46,8 @@ const CHARACTER_TYPES = {
|
|
|
46
46
|
* @typedef {Object} PasswordOptions
|
|
47
47
|
* @property {number} [min_length=15] - Minimum password length (1-72)
|
|
48
48
|
* @property {Array<'uppercase'|'lowercase'|'number'|'special'>} [character_types=[]] - Required character types
|
|
49
|
-
* @property {
|
|
50
|
-
* @property {'allow'|'
|
|
49
|
+
* @property {'all'|'three_of_four'} [character_type_rule='all'] - How many character types are required
|
|
50
|
+
* @property {'allow'|'block'} [identical_characters='allow'] - Whether to allow >2 identical consecutive characters
|
|
51
51
|
*/
|
|
52
52
|
|
|
53
53
|
/**
|
|
@@ -58,8 +58,8 @@ const CHARACTER_TYPES = {
|
|
|
58
58
|
const DEFAULT_PASSWORD_OPTIONS = {
|
|
59
59
|
min_length: 15,
|
|
60
60
|
character_types: [],
|
|
61
|
-
|
|
62
|
-
identical_characters: "
|
|
61
|
+
character_type_rule: "all",
|
|
62
|
+
identical_characters: "allow",
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
/**
|
|
@@ -76,7 +76,7 @@ function createRulesFromOptions(options = {}) {
|
|
|
76
76
|
const {
|
|
77
77
|
min_length: minLength,
|
|
78
78
|
character_types: requiredTypes,
|
|
79
|
-
|
|
79
|
+
character_type_rule: characterTypeRule,
|
|
80
80
|
identical_characters: identicalChars,
|
|
81
81
|
} = { ...DEFAULT_PASSWORD_OPTIONS, ...options };
|
|
82
82
|
|
|
@@ -88,7 +88,8 @@ function createRulesFromOptions(options = {}) {
|
|
|
88
88
|
// Handle min_length
|
|
89
89
|
rules.length = { minLength: minLength };
|
|
90
90
|
|
|
91
|
-
// Validate
|
|
91
|
+
// Validate '3 of 4' prerequisite
|
|
92
|
+
const require3of4 = characterTypeRule === "three_of_four";
|
|
92
93
|
if (require3of4) {
|
|
93
94
|
const hasAllFourTypes = Object.values(CHARACTER_TYPES).every(function (
|
|
94
95
|
type
|
|
@@ -98,7 +99,7 @@ function createRulesFromOptions(options = {}) {
|
|
|
98
99
|
|
|
99
100
|
if (!hasAllFourTypes) {
|
|
100
101
|
throw new Error(
|
|
101
|
-
`
|
|
102
|
+
`'three_of_four' character_type_rule can only be used when all four character types (${Object.values(
|
|
102
103
|
CHARACTER_TYPES
|
|
103
104
|
).join(", ")}) are selected`
|
|
104
105
|
);
|
|
@@ -135,7 +136,7 @@ function createRulesFromOptions(options = {}) {
|
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
if (identicalChars === "
|
|
139
|
+
if (identicalChars === "block") {
|
|
139
140
|
rules.identicalChars = { max: 2 };
|
|
140
141
|
}
|
|
141
142
|
|
package/package.json
CHANGED
package/test/test.js
CHANGED
|
@@ -76,11 +76,11 @@ describe("password policies", function () {
|
|
|
76
76
|
});
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
describe("
|
|
80
|
-
it("should enforce 3 out of 4 character types when all 4 types are specified", function () {
|
|
79
|
+
describe("character_type_rule", function () {
|
|
80
|
+
it("when set to 'three_of_four', should enforce 3 out of 4 character types when all 4 types are specified", function () {
|
|
81
81
|
const auth0Config = {
|
|
82
82
|
character_types: ["lowercase", "uppercase", "number", "special"],
|
|
83
|
-
|
|
83
|
+
character_type_rule: "three_of_four",
|
|
84
84
|
identical_characters: "allow",
|
|
85
85
|
min_length: 3,
|
|
86
86
|
};
|
|
@@ -100,15 +100,15 @@ describe("password policies", function () {
|
|
|
100
100
|
});
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
it("should throw an error when
|
|
103
|
+
it("when set to 'three_of_four', should throw an error when all 4 character types are NOT specified", function () {
|
|
104
104
|
expect(function () {
|
|
105
105
|
const auth0Config = {
|
|
106
106
|
character_types: ["lowercase", "uppercase"],
|
|
107
|
-
|
|
107
|
+
character_type_rule: "three_of_four",
|
|
108
108
|
};
|
|
109
109
|
createRulesFromOptions(auth0Config);
|
|
110
110
|
}).toThrow(
|
|
111
|
-
"
|
|
111
|
+
"'three_of_four' character_type_rule can only be used when all four character types (lowercase, uppercase, number, special) are selected"
|
|
112
112
|
);
|
|
113
113
|
});
|
|
114
114
|
});
|
|
@@ -116,7 +116,7 @@ describe("password policies", function () {
|
|
|
116
116
|
describe("identical_characters", function () {
|
|
117
117
|
it("should disallow more than 2 identical characters when specified", function () {
|
|
118
118
|
const auth0Config = {
|
|
119
|
-
identical_characters: "
|
|
119
|
+
identical_characters: "block",
|
|
120
120
|
};
|
|
121
121
|
const rules = createRulesFromOptions(auth0Config);
|
|
122
122
|
expect(rules).toEqual({
|
|
@@ -150,9 +150,6 @@ describe("password policies", function () {
|
|
|
150
150
|
length: {
|
|
151
151
|
minLength: 15,
|
|
152
152
|
},
|
|
153
|
-
identicalChars: {
|
|
154
|
-
max: 2,
|
|
155
|
-
},
|
|
156
153
|
});
|
|
157
154
|
});
|
|
158
155
|
|