ajout de l'updatde hashage selon algo indiqué en ver env, fix typo
Some checks reported warnings
Cadoles/hydra-sql/pipeline/pr-develop This commit is unstable

This commit is contained in:
2022-12-16 15:00:14 +01:00
parent 441c0f563c
commit bd1b035f1e
19 changed files with 247 additions and 57 deletions

View File

@ -25,17 +25,17 @@ class SQLLoginUserAuthenticator extends AbstractAuthenticator
public const LOGIN_ROUTE = 'app_login';
public const ERROR_LOGIN = 'error_login';
public const ERROR_PASSWORD = 'error_password';
public const ERROR_PDO = 'error_pdo';
public const ERROR_SQL_LOGIN = 'error_sql_login';
protected string $baseUrl;
private SQLLoginService $pdoService;
private SQLLoginService $sqlLoginService;
private UrlGeneratorInterface $router;
private PasswordEncoder $passwordHasher;
public function __construct(string $baseUrl, SQLLoginService $pdoService, UrlGeneratorInterface $router, PasswordEncoder $passwordHasher)
public function __construct(string $baseUrl, SQLLoginService $sqlLoginService, UrlGeneratorInterface $router, PasswordEncoder $passwordHasher)
{
$this->baseUrl = $baseUrl;
$this->pdoService = $pdoService;
$this->sqlLoginService = $sqlLoginService;
$this->router = $router;
$this->passwordHasher = $passwordHasher;
}
@ -72,16 +72,21 @@ class SQLLoginUserAuthenticator extends AbstractAuthenticator
$rememberMe = isset($form['_remember_me']) ? true : false;
try {
// requête préparée
list($remoteHashedPassword, $remoteSalt) = $this->pdoService->fetchPassword($login);
list($remoteHashedPassword, $remoteSalt) = $this->sqlLoginService->fetchPassword($login);
} catch (PDOException $e) {
$request->getSession()->set(self::ERROR_PDO, true);
$request->getSession()->set(self::ERROR_SQL_LOGIN, true);
throw new AuthenticationException();
}
if ($remoteHashedPassword) {
try {
// Comparaison remote hash et hash du input password + salt
// dump($remoteHashedPassword, $plaintextPassword, $remoteSalt, password_verify($plaintextPassword, $remoteHashedPassword));
$this->passwordHasher->verify($remoteHashedPassword, $plaintextPassword, $remoteSalt);
$attributes = $this->pdoService->fetchDatas($login);
if ($this->passwordHasher->needsRehash($remoteHashedPassword)) {
$hash = $this->passwordHasher->hash($plaintextPassword);
$this->sqlLoginService->updatePassword($login, $hash, null);
}
$attributes = $this->sqlLoginService->fetchDatas($login);
$user = new User($login, $remoteHashedPassword, $attributes, $rememberMe);
$loader = function (string $userIdentifier) use ($user) {
@ -98,7 +103,7 @@ class SQLLoginUserAuthenticator extends AbstractAuthenticator
$request->getSession()->set(self::ERROR_PASSWORD, true);
throw new AuthenticationException();
} catch (PDOException $e) {
$request->getSession()->set(self::ERROR_PDO, true);
$request->getSession()->set(self::ERROR_SQL_LOGIN, true);
throw new AuthenticationException();
}
}