diff --git a/src/Security/SQLLoginUserAuthenticator.php b/src/Security/SQLLoginUserAuthenticator.php index 3af54a3..0c64c59 100644 --- a/src/Security/SQLLoginUserAuthenticator.php +++ b/src/Security/SQLLoginUserAuthenticator.php @@ -11,7 +11,6 @@ use App\SQLLogin\Exception\InvalidSQLPasswordException; use App\SQLLogin\Exception\LoginElementsConfigurationException; use App\SQLLogin\Exception\SecurityPatternConfigurationException; use App\SQLLogin\SQLLoginRequest; -use Exception; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -33,15 +32,12 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator public const ERROR_SECURITY_PATTERN_CONFIGURATION = 'error_security_pattern_configuration'; private string $baseUrl; - private SQLLoginService $sqlLoginService; - private PasswordEncoder $passwordHasher; - private SQLLoginRequest $sqlLoginRequest; public function __construct( string $baseUrl, - SQLLoginService $sqlLoginService, - PasswordEncoder $passwordHasher, - SQLLoginRequest $sqlLoginRequest + private SQLLoginService $sqlLoginService, + private PasswordEncoder $passwordHasher, + private SQLLoginRequest $sqlLoginRequest ) { $this->baseUrl = $baseUrl; $this->sqlLoginService = $sqlLoginService; @@ -82,8 +78,11 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator $datas = $this->sqlLoginService->fetchPasswordAndDatas($login); $remoteHashedPassword = $datas[$this->sqlLoginRequest->getPasswordColumnName()]; unset($datas[$this->sqlLoginRequest->getPasswordColumnName()]); - $remoteSalt = $datas[$this->sqlLoginRequest->getSaltColumnName()]; - unset($datas[$this->sqlLoginRequest->getSaltColumnName()]); + $remoteSalt = null; + if ($this->sqlLoginRequest->getSaltColumnName() && isset($datas[$this->sqlLoginRequest->getSaltColumnName()])) { + $remoteSalt = $datas[$this->sqlLoginRequest->getSaltColumnName()]; + unset($datas[$this->sqlLoginRequest->getSaltColumnName()]); + } } catch (DatabaseConnectionException $e) { $session->set(self::ERROR_PDO, true); throw new AuthenticationException(); @@ -93,20 +92,15 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator } catch (DataToFetchConfigurationException $e) { $session->set(self::ERROR_DATA_TO_FETCH_CONFIGURATION, true); throw new AuthenticationException(); - } catch (Exception $exception) { - $request->getSession()->set(self::ERROR_LOGIN, true); - throw new AuthenticationException(); } if (null === $remoteHashedPassword) { $remoteHashedPassword = ''; } - try { // Comparaison remote hash et hash du input password + salt $this->passwordHasher->verify($remoteHashedPassword, $plaintextPassword, $remoteSalt); $user = new User($login, $remoteHashedPassword, $datas, $rememberMe); - $loader = function (string $userIdentifier) use ($user) { return $user->getLogin() == $userIdentifier ? $user : null; }; @@ -120,12 +114,6 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator } catch (InvalidSQLPasswordException $e) { $session->set(self::ERROR_LOGIN, true); throw new AuthenticationException(); - } catch (DataToFetchConfigurationException $e) { - $session->set(self::ERROR_DATA_TO_FETCH_CONFIGURATION, true); - throw new AuthenticationException(); - } catch (DatabaseConnectionException $e) { - $session->set(self::ERROR_PDO, true); - throw new AuthenticationException(); } catch (SecurityPatternConfigurationException $e) { $session->set(self::ERROR_SECURITY_PATTERN_CONFIGURATION, true); throw new AuthenticationException();