-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword-validator.js
More file actions
30 lines (23 loc) · 955 Bytes
/
Copy pathpassword-validator.js
File metadata and controls
30 lines (23 loc) · 955 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
27
28
29
30
function isValidPassword(password, previousPasswords) {
const lengthCondition = password.length >= 5;
console.log(`length condition: ${lengthCondition}`);
const uppercaseCondition = /[A-Z]/.test(password);
console.log(`upper case condition: ${uppercaseCondition}`);
const lowercaseCondition = /[a-z]/.test(password);
console.log(`lower case condition: ${lowercaseCondition}`);
const numberCondition = /[0-9]/.test(password);
console.log(`number condition: ${numberCondition}`);
const symbolCondition = /[!#$%.*&]/.test(password);
console.log(`symbol condition: ${symbolCondition}`);
const notInPreviousPasswords = !previousPasswords.includes(password);
console.log(`previous password condition: ${notInPreviousPasswords}`);
return (
lengthCondition &&
uppercaseCondition &&
lowercaseCondition &&
numberCondition &&
symbolCondition &&
notInPreviousPasswords
);
}
module.exports = isValidPassword;