【问题标题】:change password not working in laravel 5.4更改密码在 laravel 5.4 中不起作用
【发布时间】:2018-02-14 18:30:05
【问题描述】:

我曾尝试在 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.');
      }


    }

请告诉我代码有什么问题?

【问题讨论】:

  • 不应该bcrypt($request->new_password)]bcrypt($request->password)] 吗?

标签: laravel laravel-5.4 change-password


【解决方案1】:

您在密码验证中使用了confirmed。您需要将passwordpassword_confirmation 传入更新函数,而不是new_password

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

【讨论】:

    【解决方案2】:

    'bcrypt'新密码,然后更新。

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

    希望这对你有帮助。

    【讨论】:

      猜你喜欢
      • 2017-12-07
      • 2017-07-30
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多