Laravel Change Password with Current Password Validation

Laravel change password with current password validation; Through this tutorial, i am going to show you how to change password with current password validation in laravel apps.

Laravel Change Password with Current Password Validation Example

 The following function accepts three parameters like old password, new password and confirm password. And it will change old password to new password; is as follows:

public function updatePassword(Request $request)
{
    $this->validate($request, [
        'old_password'     => 'required',
        'new_password'     => 'required|min:6',
        'confirm_password' => 'required|same:new_password',
    ]);
 
    $data = $request->all();
  
    $user = User::find(auth()->user()->id);
 
    if(!\Hash::check($data['old_password'], $user->password)){
 
         return back()->with('error','You have entered wrong password');
 
    }else{
 
       here you will write password update code
 
    }
}

If you entered the wrong password this function returns back with your laravel route.

Recommended Laravel Tutorials

Leave a Comment