F
Filamentβ€’4mo ago
angelo

login error

:fi: help this error appears in login "this password does not use the bcrypt algorithm"
12 Replies
awcodes
awcodesβ€’4mo ago
We’re going to need more information/code to help with this.
prnl.
prnl.β€’2mo ago
I got the same error, when I look into my database the password is stored as plaintext instead of encrypted. I also have Nova running on the same project (transitioning to Filament), creating users from Nova work fine. My Filament User resource is a "simple" resource.
toeknee
toekneeβ€’2mo ago
I assume your .env APP_KEY is set? I can't see any other reason Filament would store it as plaintext since ->password() should ensure it is saved correctly.
prnl.
prnl.β€’2mo ago
APP_KEY is set in my .env
toeknee
toekneeβ€’2mo ago
and you see it as plaintext stored in the db? Can you provide your user model?
prnl.
prnl.β€’2mo ago
toeknee
toekneeβ€’2mo ago
strange, a quick fix you can chuck this on your model:
/**
* Set the user's password.
*
* @param string $value
* @return void
*/
public function setPasswordAttribute($value)
{
// Check if the value is already hashed to avoid double hashing
if (Hash::needsRehash($value)) {
$this->attributes['password'] = Hash::make($value);
} else {
$this->attributes['password'] = $value;
}
}
/**
* Set the user's password.
*
* @param string $value
* @return void
*/
public function setPasswordAttribute($value)
{
// Check if the value is already hashed to avoid double hashing
if (Hash::needsRehash($value)) {
$this->attributes['password'] = Hash::make($value);
} else {
$this->attributes['password'] = $value;
}
}
prnl.
prnl.β€’2mo ago
I have the same issue both on my development environment and my production environment. Thanks for this solution. Small, but important change πŸ™‚ if (!Hash::needsRehash($value)) { Needs to be if (Hash::needsRehash($value)) {
toeknee
toekneeβ€’2mo ago
Of course! we can thank AI for that πŸ˜›
prnl.
prnl.β€’2mo ago
Looking at the Filament\Pages\Auth\EditProfile there are some examples of setting the password, check the dehydrateStateUsing option. protected function getPasswordFormComponent(): Component { return TextInput::make('password') ->label(('filament-panels::pages/auth/edit-profile.form.password.label')) ->password() ->revealable(filament()->arePasswordsRevealable()) ->rule(Password::default()) ->autocomplete('new-password') ->dehydrated(fn ($state): bool => filled($state)) ->dehydrateStateUsing(fn ($state): string => Hash::make($state)) ->live(debounce: 500) ->same('passwordConfirmation'); } protected function getPasswordConfirmationFormComponent(): Component { return TextInput::make('passwordConfirmation') ->label(('filament-panels::pages/auth/edit-profile.form.password_confirmation.label')) ->password() ->revealable(filament()->arePasswordsRevealable()) ->required() ->visible(fn (Get $get): bool => filled($get('password'))) ->dehydrated(false); }
toeknee
toekneeβ€’2mo ago
Yep that does it too, I haven't used it as I use a jetstream one, my method does it for all possible scenarios πŸ™‚
prnl.
prnl.β€’2mo ago
True, your method is for all scenarios, nice work πŸ‘ πŸ˜€
Want results from more Discord servers?
Add your server