The best approach to personalize the password resetting feature


The Best Approach To Personalize The Password Resetting Feature

Hi guys,

We’ll look at the best approach to personalize the password resetting feature. We may tweak the Vue or react with auth after scaffolding them according to your needs. You may also change the notification class to deliver user notifications. Laravel provides convenient methods for sending password reminders and performing password resets.

Database Considerations:-

To reset the password, you need to implement the Illuminate\Contracts\Auth\CanResetPassword contract. Laravel has implemented the above contract interface. You use Illuminate\Auth\Passwords\CanResetPassword trait. After installing the laravel/ui package for your application, you run the migrate command to create a password reset to the token table.

composer require laravel/ui

php artisan migrate

Routing:-

All the necessary code is implemented on Auth\ForgotPasswordController and Auth\ResetPasswordController classes like sending emails to users and resetting the password. It generates when you have installed the laravel/ui package and scaffolded your application with frameworks like Vue, React, and Bootstrap.

composer require laravel/ui

php artisan ui vue --auth

After executing the above command, you will see the auth folder inside views.

After Resetting Passwords:-

All the logic to send an email to a user of the reset password link is included in the ForgotPasswordController Controller, and ResetPasswordController covers the rationale for resetting user passwords. After resetting a password, the user will be redirected to a dashboard page. You can customize the redirect location with the help of the redirectTo variable on the ResetPasswordController.

protected $redirectTo = '/dashboard';

You can change expire time of the password reset token inside the config/auth.php file. By default, it is one hour.

Customization:-

You can customize the included ResetPasswordController to use the guard of your choice by overriding the guard method on the controller. This method should return a guard instance.

use Illuminate\Support\Facades\Auth;

/*
 * Get the guard to be used during password reset.
 * @return \Illuminate\Contracts\Auth\StatefulGuard
 */

protected function guard()
{
    return Auth::guard('guard-name');
}

You configure multiple password brokers, which may reset the password on multiple user tables, and you can customize the included ForgotPasswordController and ResetPasswordController to use the broker of your choice by overriding the broker method.

use Illuminate\Support\Facades\Password;

/**
 * Get the broker to be used during password reset.
 * @return PasswordBroker
 */
public function broker()
{
   return Password::broker('name');
}

You may easily modify the notification class method to send a password reset link to the user by overriding the sendPasswordResetNotification method on your user model. The password reset $token is the first argument received by this method.

/**
 * Send the password reset notification.
 * @param string $token
 * @return void
 */
public function sendPasswordResetNotification($token)
{
     $this->notify(new ResetPasswordNotification($token));
}

I hope that this post (The Best Approach To Personalize The Password Resetting Feature) has helped you understand how to change the user notification and after resetting the password where a user should be redirected to the page. I used this site to write this post. Please leave a remark if you have any queries, and I will answer as quickly as possible.

Thank you for reading this article. Please share this article. That’s it for the day. Stay Connected!
Cheers,

Loading

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top