Skip to content

Commit 166eb49

Browse files
committed
Build-up a passwordValidate code
1 parent f4b337d commit 166eb49

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed
Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
1+
// List of previously used passwords
2+
const passwords = ["Abc!1", "Hello#2"];
3+
14
function passwordValidator(password) {
2-
return password.length < 5 ? false : true
3-
}
5+
// 1. Must have at least 5 characters
6+
if (password.length < 5) {
7+
return false;
8+
}
9+
10+
// 2. Must have at least one uppercase letter (A-Z)
11+
if (!/[A-Z]/.test(password)) {
12+
return false;
13+
}
14+
15+
// 3. Must have at least one lowercase letter (a-z)
16+
if (!/[a-z]/.test(password)) {
17+
return false;
18+
}
419

20+
// 4. Must have at least one number (0-9)
21+
if (!/[0-9]/.test(password)) {
22+
return false;
23+
}
24+
25+
// 5. Must have at least one symbol from the allowed list
26+
if (!/[!#$%.*&]/.test(password)) {
27+
return false;
28+
}
29+
30+
// 6. Must not be a previously used password
31+
if (passwords.includes(password)) {
32+
return false;
33+
}
34+
35+
// ✅ If all rules pass → valid
36+
return true;
37+
}
538

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

0 commit comments

Comments
 (0)