@@ -1354,7 +1354,13 @@ protected function comparePasswordHashForSPIUser(
13541354 #[\SensitiveParameter]
13551355 string $ password
13561356 ): bool {
1357- return $ this ->comparePasswordHashes ($ password , $ user ->passwordHash , $ user ->hashAlgorithm );
1357+ $ isValidPassword = $ this ->comparePasswordHashes ($ password , $ user ->passwordHash , $ user ->hashAlgorithm );
1358+
1359+ if ($ this ->passwordHashService ->updatePasswordHashTypeOnLogin ()) {
1360+ $ this ->updatePasswordHashIfNeeded ($ password , $ user ->passwordHash , $ user ->id , $ user ->login , $ user ->email );
1361+ }
1362+
1363+ return $ isValidPassword ;
13581364 }
13591365
13601366 /**
@@ -1367,7 +1373,70 @@ protected function comparePasswordHashForAPIUser(
13671373 #[\SensitiveParameter]
13681374 string $ password
13691375 ): bool {
1370- return $ this ->comparePasswordHashes ($ password , $ user ->passwordHash , $ user ->hashAlgorithm );
1376+ $ isValidPassword = $ this ->comparePasswordHashes ($ password , $ user ->passwordHash , $ user ->hashAlgorithm );
1377+
1378+ if ($ this ->passwordHashService ->updatePasswordHashTypeOnLogin ()) {
1379+ $ this ->updatePasswordHashIfNeeded ($ password , $ user ->passwordHash , $ user ->id , $ user ->login , $ user ->email );
1380+ }
1381+
1382+ return $ isValidPassword ;
1383+ }
1384+
1385+ private function updatePasswordHashIfNeeded (
1386+ #[\SensitiveParameter]
1387+ string $ password ,
1388+ #[\SensitiveParameter]
1389+ string $ passwordHash ,
1390+ int $ userId ,
1391+ string $ login ,
1392+ string $ email
1393+ ): void
1394+ {
1395+ $ defaultPasswordHashAlgorithm = $ this ->passwordHashService ->getDefaultHashType ();
1396+ if (!$ this ->passwordHashService ->passwordNeedsRehash ($ passwordHash , $ defaultPasswordHashAlgorithm )) {
1397+ return ;
1398+ }
1399+
1400+ try {
1401+ $ newPasswordHash = $ this ->passwordHashService ->createPasswordHash (
1402+ $ password ,
1403+ $ defaultPasswordHashAlgorithm
1404+ );
1405+ } catch (Exception $ e ) {
1406+ if (isset ($ this ->logger )) {
1407+ $ this ->logger ->log (LogLevel::ERROR , $ e ->getMessage (), [
1408+ 'exception ' => $ e ,
1409+ ]);
1410+ }
1411+
1412+ return ;
1413+ }
1414+
1415+ $ this ->repository ->beginTransaction ();
1416+ try {
1417+ $ this ->userHandler ->updatePassword (
1418+ new SPIUser (
1419+ [
1420+ 'id ' => $ userId ,
1421+ 'login ' => $ login ,
1422+ 'email ' => $ email ,
1423+ 'passwordHash ' => $ newPasswordHash ,
1424+ 'hashAlgorithm ' => $ defaultPasswordHashAlgorithm ,
1425+ 'passwordUpdatedAt ' => time (),
1426+ ]
1427+ )
1428+ );
1429+
1430+ $ this ->repository ->commit ();
1431+ } catch (Exception $ e ) {
1432+ $ this ->repository ->rollback ();
1433+
1434+ if (isset ($ this ->logger )) {
1435+ $ this ->logger ->log (LogLevel::ERROR , $ e ->getMessage (), [
1436+ 'exception ' => $ e ,
1437+ ]);
1438+ }
1439+ }
13711440 }
13721441
13731442 /**
0 commit comments