Why not just use a random string. This way you are not getting any unsafe characters in the token.
There should be no good reason to use the user in the token.
$reset_token = str_random(40);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I followed @bashy on this post: https://laracasts.com/discuss/channels/laravel/reset-password-manually-without-email
I am generating a token like this:
$reset_token = hash_hmac('sha256', Str::random(40), $user);
I am inserting a record in the password_resets table like this:
DB::table('password_resets')->insert([
'email' => $request->email,
'token' => $reset_token,
'created_at' => Carbon::now(),
]);
The user gets an e-mail sent through a custom notification with the correct token (it matches on the link and in the hidden input field on the view).
I keep getting this after following the link, filling in the form, and clicking on reset password:
This password reset token is invalid.
I have also tried this to generate the token (same error):
$reset_token = strtolower(str_random(64));
Not sure using notifications.
protected function registered(Request $request, $user, $reset_token) {
$user->notify(new UserRegisteredNotification($user, $reset_token)); // no need to pass user to the notification
}
Notification
public $reset_token;
public function __construct($reset_token)
{
$this->reset_token = $reset_token;
}
public function toMail($notifiable) {
$pw_reset = DB::table('password_resets')->where('email', $this->user->email)->first();
return (new MailMessage)
...
->action('Reset Password', url(config('app.url').route('password.reset', $this->reset_token, false))) // get the token from this object
...
}
Please or to participate in this conversation.