1010use YesWiki \Core \Service \UserManager ;
1111use YesWiki \Core \YesWikiAction ;
1212use YesWiki \Security \Controller \SecurityController ;
13+ use YesWiki \Core \Service \PasswordHasherFactory ;
1314
1415if (!function_exists ('send_mail ' )) {
1516 require_once ('includes/email.inc.php ' );
1617}
1718
1819class LostPasswordAction extends YesWikiAction
1920{
20- private const PW_SALT = 'FBcA ' ;
2121 public const KEY_VOCABULARY = 'http://outils-reseaux.org/_vocabulary/key ' ;
2222
2323 protected $ authController ;
2424 protected $ errorType ;
2525 protected $ typeOfRendering ;
2626 protected $ securityController ;
27+ protected $ passwordHasherFactory ;
2728 protected $ tripleStore ;
2829 protected $ userManager ;
2930
@@ -34,6 +35,7 @@ public function run()
3435 $ this ->securityController = $ this ->getService (SecurityController::class);
3536 $ this ->tripleStore = $ this ->getService (TripleStore::class);
3637 $ this ->userManager = $ this ->getService (UserManager::class);
38+ $ this ->passwordHasherFactory = $ this ->getService (PasswordHasherFactory::class);
3739
3840 // init properties
3941 $ this ->errorType = null ;
@@ -206,16 +208,18 @@ private function manageSubStep(int $subStep): ?User
206208 private function sendPasswordRecoveryEmail (User $ user )
207209 {
208210 // Generate the password recovery key
209- $ key = md5 ($ user ['name ' ] . '_ ' . $ user ['email ' ] . random_int (0 , 10000 ) . date ('Y-m-d H:i:s ' ) . self ::PW_SALT );
211+ $ passwordHasher = $ this ->passwordHasherFactory ->getPasswordHasher ($ user );
212+ $ plainKey = $ user ['name ' ] . '_ ' . $ user ['email ' ] . random_int (0 , 10000 ) . date ('Y-m-d H:i:s ' );
213+ $ hashedKey = $ passwordHasher ->hash ($ plainKey );
210214 // Erase the previous triples in the trible table
211215 $ this ->tripleStore ->delete ($ user ['name ' ], self ::KEY_VOCABULARY , null , '' , '' ) ;
212216 // Store the (name, vocabulary, key) triple in triples table
213- $ res = $ this ->tripleStore ->create ($ user ['name ' ], self ::KEY_VOCABULARY , $ key , '' , '' );
217+ $ res = $ this ->tripleStore ->create ($ user ['name ' ], self ::KEY_VOCABULARY , $ hashedKey , '' , '' );
214218
215219 // Generate the recovery email
216220 $ passwordLink = $ this ->wiki ->Href ('' , '' , [
217221 'a ' => 'recover ' ,
218- 'email ' => $ key ,
222+ 'email ' => $ hashedKey ,
219223 'u ' => base64_encode ($ user ['name ' ])
220224 ], false );
221225 $ pieces = parse_url ($ this ->params ->get ('base_url ' ));
0 commit comments