File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,13 +14,30 @@ To be valid, a password must:
1414
1515You 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 ;
You can’t perform that action at this time.
0 commit comments