Skip to content

Commit 3e569fa

Browse files
committed
Complete password-validator.js
1 parent 012c657 commit 3e569fa

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
function passwordValidator(password) {
2-
return password.length < 5 ? false : true
3-
}
2+
const previousPasswords = ["heLlo5.", "Su1ma#"];
3+
4+
const checks = {
5+
minLength: password.length > 4,
6+
hasUpperCase: /[A-Z]/.test(password),
7+
hasLowerCase: /[a-z]/.test(password),
8+
hasNumber: /[0-9]/.test(password),
9+
hasSymbol: /[!#$%.*&]/.test(password),
10+
notPreviousPassword: !previousPasswords.includes(password),
11+
};
412

13+
return Object.values(checks).every(Boolean);
14+
}
515

6-
module.exports = passwordValidator;
16+
module.exports = passwordValidator;

0 commit comments

Comments
 (0)