Skip to content

Commit d06f31f

Browse files
committed
validate the short password in the test
1 parent 2396b83 commit d06f31f

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

Sprint-3/revise/implement/password-validator.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,37 @@ You must breakdown this problem in order to solve it. Find one test case first a
1616
*/
1717

1818
function passwordValidation(password, passwords) {
19-
return (
20-
password.length >= 5 && // At least 5 characters
21-
/[A-Z]/.test(password) && // At least one uppercase letter
22-
/[a-z]/.test(password) && // At least one lowercase letter
23-
/[0-9]/.test(password) && // At least one digit
24-
/[!#$%.*&]/.test(password) && // At least one special character
25-
!passwords.includes(password) // Must not be any previous password
26-
);
27-
}
28-
module.exports = passwordValidation;
19+
// Check the password length
20+
if (password.length < 5) {
21+
return false; // Must be at least 5 characters
22+
}
23+
24+
// Check if the password contains at least one uppercase letter
25+
if (!/[A-Z]/.test(password)) {
26+
return false; // Must contain at least one uppercase letter
27+
}
28+
29+
// Check if the password contains at least one lowercase letter
30+
if (!/[a-z]/.test(password)) {
31+
return false; // Must contain at least one lowercase letter
32+
}
33+
34+
// Check if the password contains at least one digit
35+
if (!/[0-9]/.test(password)) {
36+
return false; // Must contain at least one number
37+
}
2938

39+
// Check if the password contains at least one special character
40+
if (!/[!#$%.*&]/.test(password)) {
41+
return false; // Must contain at least one non-alphanumeric symbol
42+
}
3043

44+
// Check if the password is not one of the previous passwords
45+
if (passwords.includes(password)) {
46+
return false; // Password must not be any previous password
47+
}
48+
49+
return true; // If all conditions are met, return true
50+
}
51+
52+
module.exports = passwordValidation;

Sprint-3/revise/implement/password-validator.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
const passwordValidation = require("./password-validator");
1+
const passwordValidation = require("./password-validator"); // Corrected import
22

3-
describe("passwordValidation", () => {
3+
describe("Password Validation", () => {
44
const existingPasswords = ["previousPass1", "previousPass2", "etetet"];
55

66
test("valid password with all criteria", () => {
77
expect(passwordValidation("Valid1!Test", existingPasswords)).toBe(true);
88
});
99

1010
test("password too short", () => {
11-
console.log(passwordValidation("Short1!", existingPasswords)); // Debug output
12-
expect(passwordValidation("Smjffjf!9", existingPasswords)).toBe(true);
11+
expect(passwordValidation("Shor!", existingPasswords)).toBe(false);
1312
});
1413

1514
test("password without uppercase letter", () => {

0 commit comments

Comments
 (0)