【问题标题】:Disable hashing on Auth::attempt在 Auth::attempt 上禁用散列
【发布时间】:2018-04-14 00:04:33
【问题描述】:

我正在使用一个没有散列密码的旧数据库,这个数据库也需要取消散列,因为它连接到一个可运行的 JAR。

我尽一切努力将它与 Laravel 5.3 连接起来,但它工作正常,但是.. 登录时它总是返回 false。

功能代码如下:

public function login(Request $request)
{
    $this->validate($request, [
        'account' => 'required|alpha_num|exists:accounts,account',
        'password' => 'required|alpha_num|min:4',
    ]);


    if(Auth::attempt(['account' => $request->account, 'password' => $request->password])){
        return redirect()->route('account');
    }

    return redirect()->back()->withInput();
}

我得出的结论是 Auth::attempt 通过视图对给定密码进行哈希处理,当与数据库中未哈希处理的密码进行比较时,返回 false。

我该如何解决这个问题??

谢谢。

【问题讨论】:

    标签: laravel authentication


    【解决方案1】:

    您将需要使用另一种方法manual authentication

    $user = User::where('account', $request->account)
                ->where('password', $request->password)
                ->first();
    
    if($user) {
        Auth::loginUsingId($user->id);
        // -- OR -- //
        Auth::login($user);
        return redirect()->route('account');
    } else {
        return redirect()->back()->withInput();
    }
    

    【讨论】:

      【解决方案2】:

      您只需将其添加到您的应用程序/用户即可。
      如果您在 config/hashing.php 中使用另一个驱动程序 - 将 bcrypt 更改为 argon/argon2i

      public function getAuthPassword() {
          return bcrypt($this->password);
      }

      【讨论】:

        猜你喜欢
        • 2016-01-06
        • 2015-02-08
        • 2023-03-05
        • 2013-02-27
        • 2017-05-11
        • 2018-07-30
        • 2017-03-10
        • 1970-01-01
        相关资源
        最近更新 更多