From 81bb09f4cf4e82e9f55cfac9cf1d9ad68b984919 Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Wed, 20 May 2026 11:33:18 +0100 Subject: [PATCH] Add option to disable password login (#2318) Signed-off-by: Nikolaos Karaolidis --- app/Filament/Pages/Auth/Login.php | 20 +++++++++++++++++++- config/auth.php | 2 ++ lang/en/auth.php | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Filament/Pages/Auth/Login.php b/app/Filament/Pages/Auth/Login.php index 4ee735fa1..17fa999a3 100644 --- a/app/Filament/Pages/Auth/Login.php +++ b/app/Filament/Pages/Auth/Login.php @@ -13,6 +13,7 @@ use Filament\Schemas\Components\Actions; use Filament\Schemas\Components\Component; use Filament\Schemas\Schema; use Filament\Support\Colors\Color; +use Filament\Support\Enums\Alignment; use Illuminate\Validation\ValidationException; class Login extends BaseLogin @@ -32,6 +33,12 @@ class Login extends BaseLogin public function form(Schema $schema): Schema { + if (config('auth.disable_password_login', false)) { + return $schema->components([ + $this->getOAuthFormComponent(), + ]); + } + $components = [ $this->getLoginFormComponent(), $this->getPasswordFormComponent(), @@ -108,11 +115,22 @@ class Login extends BaseLogin ->url(route('auth.oauth.redirect', ['driver' => $id], false)); } - return Actions::make($actions); + return Actions::make($actions)->alignment(fn () => config('auth.disable_password_login', false) ? Alignment::Center : null); + } + + protected function getFormActions(): array + { + return config('auth.disable_password_login', false) ? [] : parent::getFormActions(); } protected function getCredentialsFromFormData(array $data): array { + if (config('auth.disable_password_login', false)) { + throw ValidationException::withMessages([ + 'data.login' => trans('auth.password_login_disabled'), + ]); + } + $loginType = filter_var($data['login'], FILTER_VALIDATE_EMAIL) ? 'email' : 'username'; return [ diff --git a/config/auth.php b/config/auth.php index eefb4ede4..3c2a76ef7 100644 --- a/config/auth.php +++ b/config/auth.php @@ -2,6 +2,8 @@ return [ + 'disable_password_login' => env('AUTH_DISABLE_PASSWORD_LOGIN', false), + 'lockout' => [ 'time' => 2, 'attempts' => 3, diff --git a/lang/en/auth.php b/lang/en/auth.php index d88b09397..6c5cf6fda 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -20,5 +20,6 @@ return [ 'password' => 'The provided password is incorrect.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', '2fa_must_be_enabled' => 'The administrator has required that 2-Factor Authentication must be enabled for your account in order to use the Panel.', + 'password_login_disabled' => 'Password login is disabled. Please use an OAuth provider to sign in.', ];