From d57d0b07d0373399c676b2ae0c7ecfe12fdac392 Mon Sep 17 00:00:00 2001 From: Baspa Date: Wed, 28 Aug 2024 07:57:07 +0200 Subject: [PATCH 1/2] Use validate credentials before attempting to login --- src/Http/Livewire/Auth/Login.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Http/Livewire/Auth/Login.php b/src/Http/Livewire/Auth/Login.php index a494190..72a7164 100644 --- a/src/Http/Livewire/Auth/Login.php +++ b/src/Http/Livewire/Auth/Login.php @@ -102,12 +102,11 @@ public function loginWithFortify(): LoginResponse | Redirector | null $request = request()->merge($data); - if (! Filament::auth()->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false)) { + if (! $this->validateCredentials($this->getCredentialsFromFormData($data))) { $this->throwFailureValidationException(); } return $this->loginPipeline($request)->then(function (Request $request) use ($data) { - if (! Filament::auth()->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false)) { $this->throwFailureValidationException(); } @@ -177,4 +176,12 @@ protected function getAuthenticateFormAction(): Action ->label(__('filament-panels::pages/auth/login.form.actions.authenticate.label')) ->submit('authenticate'); } + + protected function validateCredentials(array $credentials): bool + { + $provider = Filament::auth()->getProvider(); + $user = $provider->retrieveByCredentials($credentials); + + return $user && $provider->validateCredentials($user, $credentials); + } } From 78d34c13fcc0f4f8173590a3dd30e512005e7717 Mon Sep 17 00:00:00 2001 From: Baspa Date: Wed, 28 Aug 2024 08:01:19 +0200 Subject: [PATCH 2/2] Set value types in iterable array --- src/Http/Livewire/Auth/Login.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Http/Livewire/Auth/Login.php b/src/Http/Livewire/Auth/Login.php index 72a7164..c80ccb7 100644 --- a/src/Http/Livewire/Auth/Login.php +++ b/src/Http/Livewire/Auth/Login.php @@ -177,6 +177,7 @@ protected function getAuthenticateFormAction(): Action ->submit('authenticate'); } + /** @param array $credentials */ protected function validateCredentials(array $credentials): bool { $provider = Filament::auth()->getProvider();