To enforce complex password requirements in Filament (such as minimum length, uppercase, numbers, symbols, etc.), you should add validation rules to your password field in the Filament form. Additionally, make sure you are hashing the password before saving it to the database.
Here's how you can do it in your Filament Resource form:
use Filament\Forms\Components\TextInput;
use Illuminate\Validation\Rules\Password;
TextInput::make('password')
->password()
->required()
->rule(Password::min(8)
->mixedCase()
->numbers()
->symbols()
->uncompromised())
->dehydrateStateUsing(fn ($state) => bcrypt($state))
->label('Password'),
Explanation:
->rule(Password::min(8)->mixedCase()->numbers()->symbols()->uncompromised())enforces a strong password policy.->dehydrateStateUsing(fn ($state) => bcrypt($state))ensures the password is hashed before saving to the database.
Note:
If you are editing a user, you might want to only hash and save the password if the field is filled. You can use ->dehydrateStateUsing conditionally or handle this in your model's mutator.
References:
This will ensure only complex, secure passwords are saved in your database.