In this tutorial, we are going to learn how to implement Change password functionality in Laravel. When you need to change your password with submit your current password, this will be the easiest way to do it.
Prerequisites
Laravel
To Continue with this tutorial, you should have installed Laravel 8 in your pc. If you are still not installed Laravel in your machine you can configure it from here.
Setting up the Project
First you need to create a new laravel project by running below command in your terminal
use Illuminate\Contracts\Validation\Rule; use Illuminate\Support\Facades\Hash;
class MatchPassword implements Rule { /** * Create a new rule instance. * * @return void */ public function __construct() { // }
/** * Determine if the validation rule passes. * * @param string $attribute * @param mixed $value * @return bool */ public function passes($attribute, $value) { return Hash::check($value, auth()->user()->password); }
/** * Get the validation error message. * * @return string */ public function message() { return 'The :attribute should match with old password.'; } }
Create ChangePasswordController
Now we need to create need to implement two functions within our controller. First function for showing our change password view and second for change password functionality. You can create your controller using following command:
In this tutorial, we implemented password change functionality in Laravel. If you have any issue regarding this tutorial, mention your issue in comment section or reach me through my E-mail. You can obtain complete source code and asset files for this tutorial from this GitHub repository.