Skip to content

Commit 2efdb62

Browse files
committed
#fix-exception-rehash pull identifier correctly, there could be many
1 parent 5af91a4 commit 2efdb62

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/Controller/Component/LoginComponent.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use Authentication\AuthenticationServiceInterface;
1818
use Authentication\Authenticator\ResultInterface;
19+
use Authentication\Identifier\IdentifierCollection;
1920
use Cake\Controller\Component;
2021
use Cake\Core\Configure;
2122
use Cake\Datasource\EntityInterface;
@@ -195,25 +196,37 @@ protected function handlePasswordRehash($service, $user, \Cake\Http\ServerReques
195196
$identifiersNames = (array)Configure::read('Auth.PasswordRehash.identifiers');
196197
foreach ($identifiersNames as $identifierName) {
197198
if (!$service->identifiers()->has($identifierName)) {
199+
Log::warning("Error saving user id $user->id password after rehashing: identifier $identifierName not found. Check your Auth.PasswordRehash.identifiers configuration.");
198200
continue;
199201
}
200202
/**
201203
* @var \Authentication\Identifier\AbstractIdentifier|null $checker
202204
*/
203205
$checker = $service->identifiers()->get($identifierName);
204206
$this->saveRehashedPassword($checker, $request, $user);
205-
break;
206207
}
207208

208209
// new way to define identifiers, inside the authenticators
209210
$authenticatorNames = (array)Configure::read('Auth.PasswordRehash.authenticators');
210-
foreach ($authenticatorNames as $authenticatorName) {
211+
foreach ($authenticatorNames as $authenticatorName => $identifierName) {
212+
if (!$service->authenticators()->has($authenticatorName)) {
213+
Log::warning("Error saving user id $user->id password after rehashing: authenticator $authenticatorName not found. Check your Auth.PasswordRehash.authenticators configuration.");
214+
continue;
215+
}
216+
/**
217+
* @var IdentifierCollection $identifierCollection
218+
*/
219+
$identifierCollection = $service->authenticators()->get($authenticatorName)->getIdentifier();
220+
if (!$identifierCollection->has($identifierName)) {
221+
Log::warning("Error saving user id $user->id password after rehashing: identifier $identifierName not found. Check your Auth.PasswordRehash.authenticators configuration.");
222+
continue;
223+
}
224+
211225
/**
212226
* @var \Authentication\Identifier\AbstractIdentifier|null $checker
213227
*/
214-
$checker = $service->authenticators()->get($authenticatorName)->getIdentifier();
228+
$checker = $identifierCollection->get($identifierName);
215229
$this->saveRehashedPassword($checker, $request, $user);
216-
break;
217230
}
218231
}
219232

0 commit comments

Comments
 (0)