Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raobilal4822's avatar

easy password saving in the data base in filament

i am working with filament. and in the user form the easy password is saving in the database but i want only the complex password should be saved according to genric password policies.

0 likes
3 replies
LaryAI's avatar

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.

jlrdw's avatar

I suggest a re-read of the documentation to ensure you are correctly creating a bcrypt password.

Please or to participate in this conversation.