@@ -78,8 +78,24 @@ private static function isExpired($token) {
7878 return true ;
7979 }
8080
81+ public static function validatePasswordStrength ($ password ) {
82+ // Validate password strength
83+ $ uppercase = preg_match ('@[A-Z]@ ' , $ password );
84+ $ lowercase = preg_match ('@[a-z]@ ' , $ password );
85+ $ number = preg_match ('@[0-9]@ ' , $ password );
86+ $ specialChars = preg_match ('@[^\w]@ ' , $ password );
87+
88+ if (!$ uppercase || !$ lowercase || !$ number || !$ specialChars || strlen ($ password ) < 8 ) {
89+ return false ;
90+ }
91+ return true ;
92+ }
93+
8194 public static function createUser ($ newUser ) {
8295 self ::connect ();
96+ if (!self ::validatePasswordStrength ($ newUser ['password ' ])) {
97+ return false ;
98+ }
8399 $ generatedUserId = md5 (random_bytes (32 ));
84100 while (self ::userIdExists ($ generatedUserId )) {
85101 $ generatedUserId = md5 (random_bytes (32 ));
@@ -107,7 +123,10 @@ public static function createUser($newUser) {
107123
108124 public static function setUserPassword ($ email , $ newPassword ) {
109125 if (!self ::userEmailExists ($ email )) {
110- return ;
126+ return false ;
127+ }
128+ if (!self ::validatePasswordStrength ($ newUser ['password ' ])) {
129+ return false ;
111130 }
112131 self ::connect ();
113132 $ query = self ::$ pdo ->prepare (
@@ -118,6 +137,7 @@ public static function setUserPassword($email, $newPassword) {
118137 $ queryParams [':passwordHash ' ] = password_hash ($ newPassword , PASSWORD_BCRYPT );
119138
120139 $ query ->execute ($ queryParams );
140+ return true ;
121141 }
122142
123143 public static function allowClientForUser ($ clientId , $ userId ) {
0 commit comments