F
Filamentβ€’3mo ago
Soundmit

Invite user and wrong credential

I have implemented an invitation workflow to send an invite to my customers and request them to insert a new password. When the user accepts the invite, I have this function to update the password.

public function create(): void
{
$this->invitationModel = UserInvitation::find($this->invitation);
$user = User::where('email', $this->invitationModel->email)->first();
$user->update([
'password' => Hash::make($this->form->getState()['password']),
'email_verified_at' => now(),

]);

auth()->login($user);
$this->invitationModel->delete();
$this->redirect('/customer');
}

public function create(): void
{
$this->invitationModel = UserInvitation::find($this->invitation);
$user = User::where('email', $this->invitationModel->email)->first();
$user->update([
'password' => Hash::make($this->form->getState()['password']),
'email_verified_at' => now(),

]);

auth()->login($user);
$this->invitationModel->delete();
$this->redirect('/customer');
}
For some reason, after setting up a new password, the user can't log in. However, if the user recovers the password, they are able to log in. I suspect there is an issue with hashing the password when the user responds to an invite.
Solution:
You double hashed the password
Jump to solution
6 Replies
Soundmit
Soundmitβ€’3mo ago
Solution
MohamedSabil83
MohamedSabil83β€’3mo ago
You double hashed the password
Soundmit
Soundmitβ€’3mo ago
double hashed... yep found just after made the post πŸ™‚ thanks!!
MohamedSabil83
MohamedSabil83β€’3mo ago
@Soundmit don't forget to set Mark Solution
Soundmit
Soundmitβ€’3mo ago
yes, in the same function the password is updated the email_verified_at not

public function create(): void
{
$this->invitationModel = UserInvitation::find($this->invitation);
$user = User::where('email', $this->invitationModel->email)->first();
$user->update([
'password' => $this->form->getState()['password'],
'email_verified_at' => 'now()',

]);

auth()->login($user);
$this->invitationModel->delete();
$this->redirect('/customer');
}

public function create(): void
{
$this->invitationModel = UserInvitation::find($this->invitation);
$user = User::where('email', $this->invitationModel->email)->first();
$user->update([
'password' => $this->form->getState()['password'],
'email_verified_at' => 'now()',

]);

auth()->login($user);
$this->invitationModel->delete();
$this->redirect('/customer');
}
how can i set mark solution?
MohamedSabil83
MohamedSabil83β€’3mo ago
Typo, now() not 'now()' Right click on the message that provide the solution, from menu go to App, and from side menu click Mark Solution