File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,35 @@ 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 previousPasswords = [ ] ; //Create an array to store previous passwords
18+
19+ function isValidPassword ( password ) {
20+ // Rule 1: At least 5 characters
21+ if ( password . length < 5 ) return false ;
22+
23+ // Rule 2: At least one uppercase letter
24+ if ( ! / [ A - Z ] / . test ( password ) ) return false ;
25+
26+ // Rule 3: At least one lowercase letter
27+ if ( ! / [ a - z ] / . test ( password ) ) return false ;
28+
29+ // Rule 4: At least one number
30+ if ( ! / [ 0 - 9 ] / . test ( password ) ) return false ;
31+
32+ // Rule 5: At least one special symbol ! # $ % . * &
33+ if ( ! / [ ! # $ % . * & ] / . test ( password ) ) return false ;
34+
35+ // Rule 6: Must not be a previous password
36+ if ( previousPasswords . includes ( password ) ) return false ;
37+
38+ // If all checks pass, save password and return true
39+ previousPasswords . push ( password ) ;
40+ return true ;
41+ }
42+
43+ module . exports = isValidPassword ;
44+
45+
1746const isValidPassword = require ( "./password-validator" ) ;
1847test ( "password has at least 5 characters" , ( ) => {
1948 // Arrange
You can’t perform that action at this time.
0 commit comments