Skip to content

Commit f190c45

Browse files
author
Ogbemi mene
committed
validation test
1 parent 669558f commit f190c45

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

Sprint-3/4-stretch/password-validator.test.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,30 @@ To be valid, a password must:
1414
1515
You must breakdown this problem in order to solve it. Find one test case first and get that working
1616
*/
17-
const isValidPassword = require("./password-validator");
18-
test("password has at least 5 characters", () => {
19-
// Arrange
20-
const password = "12345";
21-
// Act
22-
const result = isValidPassword(password);
23-
// Assert
24-
expect(result).toEqual(true);
17+
18+
const previousPasswords = [];
19+
20+
function isValidPassword(password) {
21+
// Check length
22+
if (password.length < 5) return false;
23+
24+
// Check if we already used this password
25+
if (previousPasswords.includes(password)) return false;
26+
27+
// Check for required types using simple helper logic
28+
const hasUpper = /[A-Z]/.test(password);
29+
const hasLower = /[a-z]/.test(password);
30+
const hasNumber = /[0-9]/.test(password);
31+
const hasSymbol = /[!#$%&.*]/.test(password);
32+
33+
// If all conditions are met, save it and return true
34+
if (hasUpper && hasLower && hasNumber && hasSymbol) {
35+
previousPasswords.push(password);
36+
return true;
37+
}
38+
39+
// Otherwise, it's invalid
40+
return false;
2541
}
26-
);
42+
43+
module.exports = isValidPassword;

0 commit comments

Comments
 (0)