-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword-validator.js
More file actions
26 lines (25 loc) · 802 Bytes
/
Copy pathpassword-validator.js
File metadata and controls
26 lines (25 loc) · 802 Bytes
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
function passwordValidator(
password,
usedPasswords = ["pa$$w0rd", "Qwerty1#", "Adm1n2#", "$3cr4t"]
) {
/* To be valid, a password must:
- Have at least 5 characters.
- Have at least one English uppercase letter (A-Z)
- Have at least one English lowercase letter (a-z)
- Have at least one number (0-9)
- Have at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&")
- Must not be any previous password in the passwords array.
*/
if (
password.length < 5 ||
!/[A-Z]/.test(password) ||
!/[a-z]/.test(password) ||
!/[0-9]/.test(password) ||
!/[!#$%.*&]/.test(password) ||
usedPasswords.includes(password)
) {
return false;
}
return true;
}
module.exports = passwordValidator;