@veloxts/auth 0.3.4 → 0.3.6
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 +425 -22
- package/dist/__integration__/fixtures.d.ts +41 -0
- package/dist/__integration__/fixtures.d.ts.map +1 -0
- package/dist/__integration__/fixtures.js +79 -0
- package/dist/__integration__/fixtures.js.map +1 -0
- package/dist/__integration__/setup.d.ts +26 -0
- package/dist/__integration__/setup.d.ts.map +1 -0
- package/dist/__integration__/setup.js +28 -0
- package/dist/__integration__/setup.js.map +1 -0
- package/dist/csrf.d.ts +9 -3
- package/dist/csrf.d.ts.map +1 -1
- package/dist/csrf.js +9 -3
- package/dist/csrf.js.map +1 -1
- package/dist/guards.d.ts +12 -9
- package/dist/guards.d.ts.map +1 -1
- package/dist/guards.js +17 -5
- package/dist/guards.js.map +1 -1
- package/dist/hash.d.ts +7 -1
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +20 -4
- package/dist/hash.js.map +1 -1
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -7
- package/dist/index.js.map +1 -1
- package/dist/jwt.d.ts +34 -5
- package/dist/jwt.d.ts.map +1 -1
- package/dist/jwt.js +154 -28
- package/dist/jwt.js.map +1 -1
- package/dist/middleware.d.ts +18 -6
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +23 -11
- package/dist/middleware.js.map +1 -1
- package/dist/password-policy.d.ts +259 -0
- package/dist/password-policy.d.ts.map +1 -0
- package/dist/password-policy.js +529 -0
- package/dist/password-policy.js.map +1 -0
- package/dist/plugin.d.ts +25 -7
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +28 -9
- package/dist/plugin.js.map +1 -1
- package/dist/rate-limit.d.ts +231 -0
- package/dist/rate-limit.d.ts.map +1 -0
- package/dist/rate-limit.js +352 -0
- package/dist/rate-limit.js.map +1 -0
- package/dist/session.d.ts +9 -3
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +9 -3
- package/dist/session.js.map +1 -1
- package/dist/types.d.ts +11 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +30 -7
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Password policy validation and strength scoring
|
|
3
|
+
*
|
|
4
|
+
* Provides configurable password requirements, strength scoring,
|
|
5
|
+
* common password checking, and optional breach detection.
|
|
6
|
+
*
|
|
7
|
+
* @module auth/password-policy
|
|
8
|
+
*/
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
10
|
+
/**
|
|
11
|
+
* Password strength levels
|
|
12
|
+
*/
|
|
13
|
+
export var PasswordStrength;
|
|
14
|
+
(function (PasswordStrength) {
|
|
15
|
+
PasswordStrength[PasswordStrength["VeryWeak"] = 0] = "VeryWeak";
|
|
16
|
+
PasswordStrength[PasswordStrength["Weak"] = 1] = "Weak";
|
|
17
|
+
PasswordStrength[PasswordStrength["Fair"] = 2] = "Fair";
|
|
18
|
+
PasswordStrength[PasswordStrength["Strong"] = 3] = "Strong";
|
|
19
|
+
PasswordStrength[PasswordStrength["VeryStrong"] = 4] = "VeryStrong";
|
|
20
|
+
})(PasswordStrength || (PasswordStrength = {}));
|
|
21
|
+
// ============================================================================
|
|
22
|
+
// Common Passwords List (Top 100)
|
|
23
|
+
// ============================================================================
|
|
24
|
+
/**
|
|
25
|
+
* Most common passwords to block (from NCSC/HaveIBeenPwned research)
|
|
26
|
+
*/
|
|
27
|
+
const COMMON_PASSWORDS = new Set([
|
|
28
|
+
'123456',
|
|
29
|
+
'password',
|
|
30
|
+
'12345678',
|
|
31
|
+
'qwerty',
|
|
32
|
+
'123456789',
|
|
33
|
+
'12345',
|
|
34
|
+
'1234',
|
|
35
|
+
'111111',
|
|
36
|
+
'1234567',
|
|
37
|
+
'dragon',
|
|
38
|
+
'123123',
|
|
39
|
+
'baseball',
|
|
40
|
+
'iloveyou',
|
|
41
|
+
'2000',
|
|
42
|
+
'2001',
|
|
43
|
+
'2002',
|
|
44
|
+
'2003',
|
|
45
|
+
'2004',
|
|
46
|
+
'2005',
|
|
47
|
+
'trustno1',
|
|
48
|
+
'monkey',
|
|
49
|
+
'1234567890',
|
|
50
|
+
'master',
|
|
51
|
+
'superman',
|
|
52
|
+
'qwertyuiop',
|
|
53
|
+
'654321',
|
|
54
|
+
'letmein',
|
|
55
|
+
'football',
|
|
56
|
+
'shadow',
|
|
57
|
+
'michael',
|
|
58
|
+
'jennifer',
|
|
59
|
+
'1111',
|
|
60
|
+
'2222',
|
|
61
|
+
'3333',
|
|
62
|
+
'4444',
|
|
63
|
+
'5555',
|
|
64
|
+
'6666',
|
|
65
|
+
'7777',
|
|
66
|
+
'8888',
|
|
67
|
+
'9999',
|
|
68
|
+
'0000',
|
|
69
|
+
'abc123',
|
|
70
|
+
'batman',
|
|
71
|
+
'welcome',
|
|
72
|
+
'sunshine',
|
|
73
|
+
'princess',
|
|
74
|
+
'password1',
|
|
75
|
+
'password123',
|
|
76
|
+
'admin',
|
|
77
|
+
'login',
|
|
78
|
+
'passw0rd',
|
|
79
|
+
'qwerty123',
|
|
80
|
+
'solo',
|
|
81
|
+
'starwars',
|
|
82
|
+
'whatever',
|
|
83
|
+
'charlie',
|
|
84
|
+
'donald',
|
|
85
|
+
'freedom',
|
|
86
|
+
'ginger',
|
|
87
|
+
'jordan',
|
|
88
|
+
'killer',
|
|
89
|
+
'liverpool',
|
|
90
|
+
'london',
|
|
91
|
+
'michelle',
|
|
92
|
+
'thomas',
|
|
93
|
+
'trustno',
|
|
94
|
+
'cheese',
|
|
95
|
+
'coffee',
|
|
96
|
+
'cookie',
|
|
97
|
+
'pepper',
|
|
98
|
+
'summer',
|
|
99
|
+
'winter',
|
|
100
|
+
'welcome1',
|
|
101
|
+
'access',
|
|
102
|
+
'lovely',
|
|
103
|
+
'bailey',
|
|
104
|
+
'orange',
|
|
105
|
+
'ashley',
|
|
106
|
+
'daniel',
|
|
107
|
+
'monkey1',
|
|
108
|
+
'purple',
|
|
109
|
+
'rangers',
|
|
110
|
+
'secret',
|
|
111
|
+
'secret1',
|
|
112
|
+
'test',
|
|
113
|
+
'test123',
|
|
114
|
+
'computer',
|
|
115
|
+
'internet',
|
|
116
|
+
'maverick',
|
|
117
|
+
'matrix',
|
|
118
|
+
'phoenix',
|
|
119
|
+
'thunder',
|
|
120
|
+
'zxcvbnm',
|
|
121
|
+
'hello',
|
|
122
|
+
'hello123',
|
|
123
|
+
]);
|
|
124
|
+
// ============================================================================
|
|
125
|
+
// Password Policy Class
|
|
126
|
+
// ============================================================================
|
|
127
|
+
/**
|
|
128
|
+
* Password policy validator and strength scorer
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const policy = new PasswordPolicy({
|
|
133
|
+
* minLength: 12,
|
|
134
|
+
* requireUppercase: true,
|
|
135
|
+
* requireLowercase: true,
|
|
136
|
+
* requireDigits: true,
|
|
137
|
+
* checkBreaches: true,
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* // Validate password
|
|
141
|
+
* const result = await policy.validate('MyP@ssw0rd123', {
|
|
142
|
+
* email: 'user@example.com',
|
|
143
|
+
* });
|
|
144
|
+
*
|
|
145
|
+
* if (!result.valid) {
|
|
146
|
+
* console.log('Errors:', result.errors);
|
|
147
|
+
* }
|
|
148
|
+
*
|
|
149
|
+
* console.log('Strength:', PasswordStrength[result.strength]);
|
|
150
|
+
* console.log('Score:', result.score);
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export class PasswordPolicy {
|
|
154
|
+
config;
|
|
155
|
+
constructor(config = {}) {
|
|
156
|
+
this.config = {
|
|
157
|
+
minLength: config.minLength ?? 12,
|
|
158
|
+
maxLength: config.maxLength ?? 128,
|
|
159
|
+
requireUppercase: config.requireUppercase ?? false,
|
|
160
|
+
requireLowercase: config.requireLowercase ?? false,
|
|
161
|
+
requireDigits: config.requireDigits ?? false,
|
|
162
|
+
requireSpecialChars: config.requireSpecialChars ?? false,
|
|
163
|
+
specialChars: config.specialChars ?? "!@#$%^&*()_+-=[]{}|;:,.<>?",
|
|
164
|
+
disallowCommon: config.disallowCommon ?? true,
|
|
165
|
+
checkBreaches: config.checkBreaches ?? false,
|
|
166
|
+
maxBreachOccurrences: config.maxBreachOccurrences ?? 0,
|
|
167
|
+
blacklist: config.blacklist ?? [],
|
|
168
|
+
disallowUserInfo: config.disallowUserInfo ?? true,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Validate a password against the policy
|
|
173
|
+
*
|
|
174
|
+
* @param password - Password to validate
|
|
175
|
+
* @param userInfo - Optional user information to check against
|
|
176
|
+
* @returns Validation result with errors and strength score
|
|
177
|
+
*/
|
|
178
|
+
async validate(password, userInfo) {
|
|
179
|
+
const errors = [];
|
|
180
|
+
// Length requirements
|
|
181
|
+
if (password.length < this.config.minLength) {
|
|
182
|
+
errors.push(`Password must be at least ${this.config.minLength} characters long`);
|
|
183
|
+
}
|
|
184
|
+
if (this.config.maxLength > 0 && password.length > this.config.maxLength) {
|
|
185
|
+
errors.push(`Password must not exceed ${this.config.maxLength} characters`);
|
|
186
|
+
}
|
|
187
|
+
// Character requirements
|
|
188
|
+
if (this.config.requireUppercase && !/[A-Z]/.test(password)) {
|
|
189
|
+
errors.push('Password must contain at least one uppercase letter');
|
|
190
|
+
}
|
|
191
|
+
if (this.config.requireLowercase && !/[a-z]/.test(password)) {
|
|
192
|
+
errors.push('Password must contain at least one lowercase letter');
|
|
193
|
+
}
|
|
194
|
+
if (this.config.requireDigits && !/\d/.test(password)) {
|
|
195
|
+
errors.push('Password must contain at least one digit');
|
|
196
|
+
}
|
|
197
|
+
if (this.config.requireSpecialChars) {
|
|
198
|
+
const specialCharsRegex = new RegExp(`[${escapeRegex(this.config.specialChars)}]`);
|
|
199
|
+
if (!specialCharsRegex.test(password)) {
|
|
200
|
+
errors.push('Password must contain at least one special character');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Common password check
|
|
204
|
+
if (this.config.disallowCommon) {
|
|
205
|
+
const lowerPassword = password.toLowerCase();
|
|
206
|
+
if (COMMON_PASSWORDS.has(lowerPassword)) {
|
|
207
|
+
errors.push('Password is too common and easily guessable');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Custom blacklist check
|
|
211
|
+
if (this.config.blacklist.length > 0) {
|
|
212
|
+
const lowerPassword = password.toLowerCase();
|
|
213
|
+
for (const banned of this.config.blacklist) {
|
|
214
|
+
if (lowerPassword === banned.toLowerCase()) {
|
|
215
|
+
errors.push('Password is not allowed');
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// User information check
|
|
221
|
+
if (this.config.disallowUserInfo && userInfo) {
|
|
222
|
+
const lowerPassword = password.toLowerCase();
|
|
223
|
+
const infoValues = Object.values(userInfo).filter((v) => typeof v === 'string' && v.length > 0);
|
|
224
|
+
for (const value of infoValues) {
|
|
225
|
+
const lowerValue = value.toLowerCase();
|
|
226
|
+
// Check if password contains user info
|
|
227
|
+
if (lowerPassword.includes(lowerValue)) {
|
|
228
|
+
errors.push('Password must not contain personal information');
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
// Check if password is similar to email username
|
|
232
|
+
if (value.includes('@')) {
|
|
233
|
+
const username = value.split('@')[0].toLowerCase();
|
|
234
|
+
if (username.length >= 3 && lowerPassword.includes(username)) {
|
|
235
|
+
errors.push('Password must not contain personal information');
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// Strength score
|
|
242
|
+
const { score, strength } = this.calculateStrength(password);
|
|
243
|
+
// Breach check (async)
|
|
244
|
+
let breached;
|
|
245
|
+
let breachCount;
|
|
246
|
+
if (this.config.checkBreaches) {
|
|
247
|
+
try {
|
|
248
|
+
breachCount = await this.checkBreaches(password);
|
|
249
|
+
breached = breachCount > this.config.maxBreachOccurrences;
|
|
250
|
+
if (breached) {
|
|
251
|
+
errors.push(`Password has been found in ${breachCount} data breaches and is not secure`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
// Breach check failed - log but don't fail validation
|
|
256
|
+
console.warn('Password breach check failed:', error);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
valid: errors.length === 0,
|
|
261
|
+
errors,
|
|
262
|
+
strength,
|
|
263
|
+
score,
|
|
264
|
+
breached,
|
|
265
|
+
breachCount,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Calculate password strength score (0-100) and level (0-4)
|
|
270
|
+
*
|
|
271
|
+
* Based on:
|
|
272
|
+
* - Length
|
|
273
|
+
* - Character variety (uppercase, lowercase, digits, special)
|
|
274
|
+
* - Entropy
|
|
275
|
+
* - Pattern detection
|
|
276
|
+
*/
|
|
277
|
+
calculateStrength(password) {
|
|
278
|
+
let score = 0;
|
|
279
|
+
// Length scoring (up to 30 points)
|
|
280
|
+
if (password.length >= 8)
|
|
281
|
+
score += 10;
|
|
282
|
+
if (password.length >= 12)
|
|
283
|
+
score += 10;
|
|
284
|
+
if (password.length >= 16)
|
|
285
|
+
score += 5;
|
|
286
|
+
if (password.length >= 20)
|
|
287
|
+
score += 5;
|
|
288
|
+
// Character variety (up to 40 points)
|
|
289
|
+
const hasLower = /[a-z]/.test(password);
|
|
290
|
+
const hasUpper = /[A-Z]/.test(password);
|
|
291
|
+
const hasDigit = /\d/.test(password);
|
|
292
|
+
const hasSpecial = /[^a-zA-Z0-9]/.test(password);
|
|
293
|
+
const varietyCount = [hasLower, hasUpper, hasDigit, hasSpecial].filter(Boolean).length;
|
|
294
|
+
score += varietyCount * 10;
|
|
295
|
+
// Entropy bonus (up to 20 points)
|
|
296
|
+
const entropy = this.calculateEntropy(password);
|
|
297
|
+
if (entropy >= 30)
|
|
298
|
+
score += 5;
|
|
299
|
+
if (entropy >= 40)
|
|
300
|
+
score += 5;
|
|
301
|
+
if (entropy >= 50)
|
|
302
|
+
score += 5;
|
|
303
|
+
if (entropy >= 60)
|
|
304
|
+
score += 5;
|
|
305
|
+
// Pattern penalties (up to -20 points)
|
|
306
|
+
if (/(.)\1{2,}/.test(password))
|
|
307
|
+
score -= 5; // Repeated characters (aaa, 111)
|
|
308
|
+
if (/^[a-z]+$/.test(password))
|
|
309
|
+
score -= 5; // Only lowercase
|
|
310
|
+
if (/^[A-Z]+$/.test(password))
|
|
311
|
+
score -= 5; // Only uppercase
|
|
312
|
+
if (/^\d+$/.test(password))
|
|
313
|
+
score -= 10; // Only digits
|
|
314
|
+
if (/^(012|123|234|345|456|567|678|789|890)/.test(password))
|
|
315
|
+
score -= 5; // Sequential
|
|
316
|
+
// Bonus for mixing character positions (up to 10 points)
|
|
317
|
+
const mixedPositions = this.checkMixedPositions(password);
|
|
318
|
+
if (mixedPositions)
|
|
319
|
+
score += 10;
|
|
320
|
+
// Ensure score is within bounds
|
|
321
|
+
score = Math.max(0, Math.min(100, score));
|
|
322
|
+
// Convert score to strength level
|
|
323
|
+
let strength;
|
|
324
|
+
if (score < 20)
|
|
325
|
+
strength = PasswordStrength.VeryWeak;
|
|
326
|
+
else if (score < 40)
|
|
327
|
+
strength = PasswordStrength.Weak;
|
|
328
|
+
else if (score < 60)
|
|
329
|
+
strength = PasswordStrength.Fair;
|
|
330
|
+
else if (score < 80)
|
|
331
|
+
strength = PasswordStrength.Strong;
|
|
332
|
+
else
|
|
333
|
+
strength = PasswordStrength.VeryStrong;
|
|
334
|
+
return { score, strength };
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Calculate Shannon entropy of password
|
|
338
|
+
*/
|
|
339
|
+
calculateEntropy(password) {
|
|
340
|
+
const charCounts = new Map();
|
|
341
|
+
for (const char of password) {
|
|
342
|
+
charCounts.set(char, (charCounts.get(char) ?? 0) + 1);
|
|
343
|
+
}
|
|
344
|
+
let entropy = 0;
|
|
345
|
+
const length = password.length;
|
|
346
|
+
for (const count of charCounts.values()) {
|
|
347
|
+
const probability = count / length;
|
|
348
|
+
entropy -= probability * Math.log2(probability);
|
|
349
|
+
}
|
|
350
|
+
return entropy * length;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Check if character types are well-mixed (not clustered)
|
|
354
|
+
*/
|
|
355
|
+
checkMixedPositions(password) {
|
|
356
|
+
if (password.length < 4)
|
|
357
|
+
return false;
|
|
358
|
+
const quarters = [
|
|
359
|
+
password.slice(0, Math.floor(password.length / 4)),
|
|
360
|
+
password.slice(Math.floor(password.length / 4), Math.floor(password.length / 2)),
|
|
361
|
+
password.slice(Math.floor(password.length / 2), Math.floor((3 * password.length) / 4)),
|
|
362
|
+
password.slice(Math.floor((3 * password.length) / 4)),
|
|
363
|
+
];
|
|
364
|
+
// Check that each quarter has some variety
|
|
365
|
+
let varietyQuarters = 0;
|
|
366
|
+
for (const quarter of quarters) {
|
|
367
|
+
const hasAlpha = /[a-zA-Z]/.test(quarter);
|
|
368
|
+
const hasDigit = /\d/.test(quarter);
|
|
369
|
+
const hasSpecial = /[^a-zA-Z0-9]/.test(quarter);
|
|
370
|
+
if ([hasAlpha, hasDigit, hasSpecial].filter(Boolean).length >= 2) {
|
|
371
|
+
varietyQuarters++;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return varietyQuarters >= 3;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Check password against Have I Been Pwned API
|
|
378
|
+
*
|
|
379
|
+
* Uses k-anonymity: only sends first 5 chars of SHA-1 hash
|
|
380
|
+
* to protect password privacy.
|
|
381
|
+
*
|
|
382
|
+
* @returns Number of times password appears in breaches (0 = not found)
|
|
383
|
+
*/
|
|
384
|
+
async checkBreaches(password) {
|
|
385
|
+
// Hash password with SHA-1
|
|
386
|
+
const hash = createHash('sha1').update(password).digest('hex').toUpperCase();
|
|
387
|
+
const prefix = hash.slice(0, 5);
|
|
388
|
+
const suffix = hash.slice(5);
|
|
389
|
+
// Query API with hash prefix
|
|
390
|
+
const response = await fetch(`https://api.pwnedpasswords.com/range/${prefix}`, {
|
|
391
|
+
headers: {
|
|
392
|
+
'User-Agent': 'VeloxTS-Auth-Password-Policy',
|
|
393
|
+
},
|
|
394
|
+
});
|
|
395
|
+
if (!response.ok) {
|
|
396
|
+
throw new Error(`HaveIBeenPwned API error: ${response.status}`);
|
|
397
|
+
}
|
|
398
|
+
const text = await response.text();
|
|
399
|
+
const lines = text.split('\n');
|
|
400
|
+
// Search for our suffix in results
|
|
401
|
+
for (const line of lines) {
|
|
402
|
+
const [hashSuffix, countStr] = line.split(':');
|
|
403
|
+
if (hashSuffix === suffix) {
|
|
404
|
+
return parseInt(countStr.trim(), 10);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return 0; // Not found in breaches
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Get password strength as human-readable string
|
|
411
|
+
*/
|
|
412
|
+
getStrengthLabel(strength) {
|
|
413
|
+
switch (strength) {
|
|
414
|
+
case PasswordStrength.VeryWeak:
|
|
415
|
+
return 'Very Weak';
|
|
416
|
+
case PasswordStrength.Weak:
|
|
417
|
+
return 'Weak';
|
|
418
|
+
case PasswordStrength.Fair:
|
|
419
|
+
return 'Fair';
|
|
420
|
+
case PasswordStrength.Strong:
|
|
421
|
+
return 'Strong';
|
|
422
|
+
case PasswordStrength.VeryStrong:
|
|
423
|
+
return 'Very Strong';
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Get password strength color (for UI display)
|
|
428
|
+
*/
|
|
429
|
+
getStrengthColor(strength) {
|
|
430
|
+
switch (strength) {
|
|
431
|
+
case PasswordStrength.VeryWeak:
|
|
432
|
+
return '#d73a49'; // Red
|
|
433
|
+
case PasswordStrength.Weak:
|
|
434
|
+
return '#e36209'; // Orange
|
|
435
|
+
case PasswordStrength.Fair:
|
|
436
|
+
return '#ffd33d'; // Yellow
|
|
437
|
+
case PasswordStrength.Strong:
|
|
438
|
+
return '#28a745'; // Green
|
|
439
|
+
case PasswordStrength.VeryStrong:
|
|
440
|
+
return '#0366d6'; // Blue
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
// ============================================================================
|
|
445
|
+
// Helper Functions
|
|
446
|
+
// ============================================================================
|
|
447
|
+
/**
|
|
448
|
+
* Escape special characters for regex
|
|
449
|
+
*/
|
|
450
|
+
function escapeRegex(str) {
|
|
451
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
452
|
+
}
|
|
453
|
+
// ============================================================================
|
|
454
|
+
// Convenience Exports
|
|
455
|
+
// ============================================================================
|
|
456
|
+
/**
|
|
457
|
+
* Create a password policy validator (succinct API)
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* ```typescript
|
|
461
|
+
* import { passwordPolicy } from '@veloxts/auth';
|
|
462
|
+
*
|
|
463
|
+
* const policy = passwordPolicy({
|
|
464
|
+
* minLength: 12,
|
|
465
|
+
* requireUppercase: true,
|
|
466
|
+
* requireDigits: true,
|
|
467
|
+
* });
|
|
468
|
+
*
|
|
469
|
+
* const result = await policy.validate('MyPassword123');
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
export function passwordPolicy(config) {
|
|
473
|
+
return new PasswordPolicy(config);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Creates a password policy validator
|
|
477
|
+
*
|
|
478
|
+
* @deprecated Use `passwordPolicy()` instead. Will be removed in v0.9.
|
|
479
|
+
*/
|
|
480
|
+
export const createPasswordPolicy = passwordPolicy;
|
|
481
|
+
/**
|
|
482
|
+
* Quick password strength check (no policy validation)
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```typescript
|
|
486
|
+
* import { checkPasswordStrength } from '@veloxts/auth';
|
|
487
|
+
*
|
|
488
|
+
* const { strength, score } = checkPasswordStrength('MyP@ssw0rd123');
|
|
489
|
+
* console.log(PasswordStrength[strength]); // "Strong"
|
|
490
|
+
* console.log(score); // 75
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
export function checkPasswordStrength(password) {
|
|
494
|
+
const policy = new PasswordPolicy();
|
|
495
|
+
return policy.calculateStrength(password);
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Quick common password check
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```typescript
|
|
502
|
+
* import { isCommonPassword } from '@veloxts/auth';
|
|
503
|
+
*
|
|
504
|
+
* if (isCommonPassword('password123')) {
|
|
505
|
+
* console.log('Please choose a more secure password');
|
|
506
|
+
* }
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
export function isCommonPassword(password) {
|
|
510
|
+
return COMMON_PASSWORDS.has(password.toLowerCase());
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Check password against Have I Been Pwned
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* ```typescript
|
|
517
|
+
* import { checkPasswordBreach } from '@veloxts/auth';
|
|
518
|
+
*
|
|
519
|
+
* const count = await checkPasswordBreach('password123');
|
|
520
|
+
* if (count > 0) {
|
|
521
|
+
* console.log(`Found in ${count} breaches!`);
|
|
522
|
+
* }
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
export async function checkPasswordBreach(password) {
|
|
526
|
+
const policy = new PasswordPolicy();
|
|
527
|
+
return policy['checkBreaches'](password);
|
|
528
|
+
}
|
|
529
|
+
//# sourceMappingURL=password-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-policy.js","sourceRoot":"","sources":["../src/password-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAoFzC;;GAEG;AACH,MAAM,CAAN,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,+DA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;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAAC,MAA6B;IAC1D,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAgB;IAEhB,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,OAAO,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,QAAgB;IACxD,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ declare module 'fastify' {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* Creates the VeloxTS auth plugin
|
|
63
|
+
* Creates the VeloxTS auth plugin (succinct API)
|
|
64
64
|
*
|
|
65
65
|
* This plugin provides:
|
|
66
66
|
* - JWT token management (access + refresh tokens)
|
|
@@ -70,9 +70,9 @@ declare module 'fastify' {
|
|
|
70
70
|
*
|
|
71
71
|
* @example
|
|
72
72
|
* ```typescript
|
|
73
|
-
* import {
|
|
73
|
+
* import { authPlugin } from '@veloxts/auth';
|
|
74
74
|
*
|
|
75
|
-
* const
|
|
75
|
+
* const auth = authPlugin({
|
|
76
76
|
* jwt: {
|
|
77
77
|
* secret: process.env.JWT_SECRET!,
|
|
78
78
|
* accessTokenExpiry: '15m',
|
|
@@ -88,7 +88,7 @@ declare module 'fastify' {
|
|
|
88
88
|
* });
|
|
89
89
|
*
|
|
90
90
|
* // Register with VeloxApp
|
|
91
|
-
* app.register(
|
|
91
|
+
* await app.register(auth);
|
|
92
92
|
*
|
|
93
93
|
* // Use in procedures
|
|
94
94
|
* const { middleware, requireAuth } = app.auth.middleware;
|
|
@@ -98,10 +98,28 @@ declare module 'fastify' {
|
|
|
98
98
|
* .query(async ({ ctx }) => ctx.user);
|
|
99
99
|
* ```
|
|
100
100
|
*/
|
|
101
|
-
export declare function
|
|
101
|
+
export declare function authPlugin(options: AuthPluginOptions): VeloxPlugin<AuthPluginOptions>;
|
|
102
|
+
/**
|
|
103
|
+
* Creates the VeloxTS auth plugin
|
|
104
|
+
*
|
|
105
|
+
* @deprecated Use `authPlugin()` instead. Will be removed in v0.9.
|
|
106
|
+
*/
|
|
107
|
+
export declare const createAuthPlugin: typeof authPlugin;
|
|
102
108
|
/**
|
|
103
109
|
* Default auth plugin with minimal configuration
|
|
104
|
-
*
|
|
110
|
+
*
|
|
111
|
+
* Uses environment variables for configuration:
|
|
112
|
+
* - `JWT_SECRET` (required): Secret for signing JWT tokens
|
|
113
|
+
*
|
|
114
|
+
* @throws {Error} If JWT_SECRET environment variable is not set
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import { defaultAuthPlugin } from '@veloxts/auth';
|
|
119
|
+
*
|
|
120
|
+
* // Requires JWT_SECRET environment variable
|
|
121
|
+
* await app.register(defaultAuthPlugin());
|
|
122
|
+
* ```
|
|
105
123
|
*/
|
|
106
|
-
export declare function
|
|
124
|
+
export declare function defaultAuthPlugin(): VeloxPlugin<AuthPluginOptions>;
|
|
107
125
|
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{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