2017-09-06 287 views
0

我试图改变密码laravel 5.4它成功改变,但之后,当我想再次用新密码登录它引发错误凭据不匹配。更改密码不工作laravel 5.4

这里是我的代码 -

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.'); 
     } 


    } 

请让我知道什么是错的代码?

+0

不应'bcrypt($ request-> new_password)]'bcrypt($ request-> password)]'? – linktoahref

回答

0

您已在密码验证中使用confirmed。您需要在passwordpassword_confirmation通入更新功能,而不是new_password

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

0

bcrypt”的新密码,然后对其进行更新。

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

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

希望这会对你有所帮助。