Open
Description
I would like to check the logged-in user with every request to see if their email address or password has changed. If a user changes their password, every existing session should also be terminated.
This should apparently be possible to solve with identify => true in the SessionAuthenticator. However, if I enable this, the session is always terminated because, in the following lines, the hashed password from the session is hashed again and compared with the hashed password from the database, which results in a FAILURE_CREDENTIALS_INVALID result. Please also see attached file.
SessionAuthenticator.php :
if ($this->getConfig('identify') === true) {
$credentials = [];
foreach ($this->getConfig('fields') as $key => $field) {
$credentials[$key] = $user[$field];
}
$user = $this->_identifier->identify($credentials);
if (empty($user)) {
return new Result(null, Result::FAILURE_CREDENTIALS_INVALID);
}
}
The login remains unsuccessful if I try to log in without cookies.
Here is my configuration:
$authenticationService->loadAuthenticator('Authentication.Session', [
// identify option reads current user information from database and put it into request's identity attribute, not refresh's the session!
'identify' => true,
'fields' => [
AbstractIdentifier::CREDENTIAL_USERNAME => 'email',
AbstractIdentifier::CREDENTIAL_PASSWORD => 'password',
],
]);
// Configure form data check to pick email and password
$authenticationService->loadAuthenticator('Authentication.Form', [
'fields' => [
AbstractIdentifier::CREDENTIAL_USERNAME => 'email',
AbstractIdentifier::CREDENTIAL_PASSWORD => 'password',
],
'loginUrl' => '/users/login',
]);
// If the user is on the login page, check for a cookie as well
$authenticationService->loadAuthenticator('Authentication.Cookie', [
'fields' => [
AbstractIdentifier::CREDENTIAL_USERNAME => 'email',
AbstractIdentifier::CREDENTIAL_PASSWORD => 'password',
],
'cookie' => [
'name' => 'CookieAuth',
'domain' => COOKIE_DOMAIN,
'expires' => (new DateTime())->addDays(30),
],
'loginUrl' => '/users/login',
]);
// Load identifiers, ensure we check username and password fields
$authenticationService->loadIdentifier('Authentication.Password', [
'resolver' => [
'className' => 'Authentication.Orm',
'finder' => 'authenticatedUser'
],
'fields' => [
AbstractIdentifier::CREDENTIAL_USERNAME => 'email',
AbstractIdentifier::CREDENTIAL_PASSWORD => 'password',
],
'passwordHasher' => [
'className' => 'Authentication.Fallback',
'hashers' => [
'Authentication.Default',
[
'className' => 'Authentication.Legacy',
'hashType' => 'md5',
'salt' => false // turn off default usage of salt
],
]
]
]);
Metadata
Metadata
Assignees
Labels
No labels