Skip to content

Commit 094657b

Browse files
committed
Update: fix password validation logic and comment out test cases
1 parent d0371be commit 094657b

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed
Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
1-
function passwordValidator(password) {
2-
return password.length < 5 ? false : true
3-
}
1+
// function passwordValidator(password) {
2+
// return password.length < 5 ? false : true;
3+
// }
4+
5+
// module.exports = passwordValidator;
6+
const previousPasswords = ["Password123!", "Welcome2023$", "Admin*1"];
47

8+
function isValidPassword(password) {
9+
const hasMinLength = password.length >= 5;
10+
const hasUppercase = /[A-Z]/.test(password);
11+
const hasLowercase = /[a-z]/.test(password);
12+
const hasDigit = /[0-9]/.test(password);
13+
const hasSymbol = /[!#$%.*&]/.test(password);
14+
const isNotPrevious = !previousPasswords.includes(password);
15+
16+
return (
17+
hasMinLength &&
18+
hasUppercase &&
19+
hasLowercase &&
20+
hasDigit &&
21+
hasSymbol &&
22+
isNotPrevious
23+
);
24+
}
525

6-
module.exports = passwordValidator;
26+
module.exports = isValidPassword;
27+
// Example usage:
28+
// console.log(isValidPassword("Abdi10!")); // true
29+
// console.log(isValidPassword("12345")); // false
30+
// console.log(isValidPassword("123")); // false
31+
// console.log(isValidPassword("abcde")); // false
32+
// console.log(isValidPassword("")); // false

0 commit comments

Comments
 (0)