change password not working in laravel 5.4

813 Views Asked by At

i have tried to change password in laravel 5.4 it changed successfully but after that when i am trying to login again with new password it throws an error credential do not match.

here is my code-

public function UpdatePassword(Request $request)
    {
      $this->validate($request, [
             'old_password' => 'required',
             'password' => 'required|string|min:6|confirmed',

        ]); 
      $old_password = $request->old_password;
      if (Hash::check($old_password, Auth::user()->password)) {
          # code...

        Auth::user()->update(['password'=>bcrypt($request->new_password)]);

        return back()->with('message','password chnaged successfully.');

      } else {
          # code...
        return back()->with('message_error','Please Enter Correct Old Password.');
      }


    }

please let me know whats wrong with code?

2

There are 2 best solutions below

0
On

You've used confirmed in the password validation. You will need to pass in password or password_confirmation into the update function, not new_password

Auth::user()->update(['password'=>bcrypt($request->password_confirmation)]);

0
On

'bcrypt' the new password and then update it.

    $password = bcrypt(Input::get('password'));
    $user     = User::where('email', $request->email)->first();
    if ($user) {

        $user->password = $password;
        $user->save();
     }

Hope this will helpful for you.