【问题标题】:Laravel bcrypt password not matching in lumenLaravel bcrypt 密码在流明中不匹配
【发布时间】:2019-09-05 23:12:57
【问题描述】:

我在数据库中使用 bcrypt() 密码创建了许多使用 laravel 的用户,现在我正在构建 JWT 基础身份验证的 lumen 中编写 API

我的代码看起来像

$credentials = [
    'email' => $this->request->input('email'),
    'password' => $this->request->input('password'),
];

if (Auth::check($credentials)) {
    dd('success');
} else {
    dd('failed');
}

失败,进入条件的 else 部分

我也尝试过 Hash::check,但它也给了我错误

if (Hash::check($this->request->input('password'), $user->password)) {
    return response()->json([
        'token' => $this->jwt($user)
    ], 200);
}

注意:我在请求中传递的密码是正确的。

我在这里做错了什么,缺少什么

【问题讨论】:

  • 这两个是独立的应用程序吗?如果是这样,bcrypt(如果我没记错的话)使用 .env 文件中的 APP_KEY 进行加密,你可以让那些不匹配。
  • @JCode 仍然无法使用,应用已更改
  • @JCode 我已经匹配了应用键,复制粘贴了,但是还是不行
  • 您是否确认 Laravel 和 Lumen 都以相同的方式检查您正在使用的版本的哈希和密码?
  • @Gammer 你解决了吗?

标签: php laravel authentication jwt lumen


【解决方案1】:

你试过attempt()而不是check

public function login(Request $request)
{
    $credentials = $request->only('email', 'password');

    if ($token = $this->guard()->attempt($credentials)) {
        return $this->respondWithToken($token);
    }

    return response()->json(['error' => 'Unauthorized'], 401);
}

检查documentation

您可能需要使用

编辑您的 .env 文件
AUTH_DRIVER=eloquent
AUTH_MODEL=\App\Models\User
AUTH_TABLE=users

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-09
    • 2021-08-29
    • 2015-04-05
    • 2018-06-30
    • 2020-01-07
    • 2014-05-08
    • 1970-01-01
    • 2020-11-23
    相关资源
    最近更新 更多