Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel Lumen,验证尝试始终返回false(jwt或auth)_Laravel_Authentication_Laravel 5_Jwt_Lumen - Fatal编程技术网

Laravel Lumen,验证尝试始终返回false(jwt或auth)

Laravel Lumen,验证尝试始终返回false(jwt或auth),laravel,authentication,laravel-5,jwt,lumen,Laravel,Authentication,Laravel 5,Jwt,Lumen,我用php lumen框架制作了一个小API 现在我正在为我的应用程序集成一个jwt身份验证(遵循这个图图),但是当我尝试登录时,它总是返回false jwt似乎没有直接的问题,因为令牌生成工作,但只有登录不工作。正如我看到的,jwt使用Lumen Auth::登录,因此为了确保我尝试直接使用Auth::trunt()登录,而不是使用JWTAuth::trunt,但结果也是false。。。 这是我的密码: try { $validation = $this->validate($re

我用php lumen框架制作了一个小API

现在我正在为我的应用程序集成一个jwt身份验证(遵循这个图图),但是当我尝试登录时,它总是返回false

jwt
似乎没有直接的问题,因为令牌生成工作,但只有登录不工作。正如我看到的,
jwt
使用
Lumen Auth::
登录,因此为了确保我尝试直接使用
Auth::trunt()
登录,而不是使用
JWTAuth::trunt
,但结果也是
false
。。。 这是我的密码:

try
{
   $validation = $this->validate($request, [
      'email'    => 'required|email',
      'password' => 'required'
   ]);

   $credentials = $request->only('email', 'password');

   $isAuthenticated = Auth::attempt($credentials) || JWTAuth::attempt($credentials);

   $user = User::first();
   $token = JWTAuth::fromUser($user);

   $result = [
     'isAuthenticated' => $isAuthenticated,
     'token' => $token
   ];
 // ... catch exceptions + return $result or errors from exceptions
我进行了一些搜索,以纠正此类问题的常见错误,我已经检查过:

  • 我有一个名为
    users
  • 其中我有一个
    密码
    列和一个
    电子邮件
    列(小写全名)
  • db
    password
    列为varchar(140)
  • 并尝试创建和登录如下用户:

    $user = new User;
    $user->email = 'example@domain.com';
    $user->password = Hash::make('passwordExample');
    $user->save();
    //And login with it:
    $userData = array(
      'email' => 'example@domain.com',
      'password' => 'passwordExample');            
    return (string) Auth::attempt($userData));
    
    • 我的身份验证配置包含:
    'driver'=>env('AUTH_driver','elount'), 'model'=>env('AUTH_model','App\Models\User'), 'table'=>env('AUTH_table','users')

    • my
      App\Models\User
      model
      implements Illumb\Contracts\Authenticatable
      并使用
      Illumb\Authenticatable
但是没有变化。。。我总是得到一个“假”! 有什么问题吗

以下是我使用的框架版本(来自composer.json)


注意:我还注意到,对同一个密码进行两次哈希运算,结果是不一样的。正如我所读到的,这是正常的,Auth知道如何检查散列存储的密码。但我不明白。。。如果哈希结果不同,他如何检查密码?它为每个哈希存储一个盐?

那么。。。花了我一段时间,但我知道如何正确登录

如果我未对密码进行哈希设置:

$user = User::select('id', 'email')
  ->where('email', $email)
  ->first();
$user->password = $newPassword;
$user->save();
我在数据库中查看插入的内容,密码是加密存储的

然后,如果我尝试使用以下方式登录:

$this->validate($request, [
    'email'    => 'required|email|max:255',
    'password' => 'required'
]);
$credentials = $request->only('email', 'password');
if ( $token = JWTAuth::attempt($credentials) )
...
它工作正常

所以我的问题是,在插入密码之前,我对密码进行了两次哈希运算

但我真的不明白为什么它会自动散列,因为正如我在文档中看到的,我必须明确地进行散列。因此,如果有人能给我一个理由,我会非常感兴趣知道它


无论如何,我应该直接使用
Hash::needsReshash($hashed)

->这并没有解决我的问题,但已经回答了我的注释问题
.env
文件中是否也设置了配置变量?如果是这样,他们将覆盖
/config
文件夹中的内容。@Jeemusu感谢您的回复。
.env
的值与
/config
的值相同。我试图删除条目,以便只允许来自
auth config
的值,但这并没有解决问题。太棒了!非常感谢。也帮助了我<代码>身份验证::尝试(['email'=>'user@domain.com“,”密码“=>”123456'])返回false
$this->validate($request, [
    'email'    => 'required|email|max:255',
    'password' => 'required'
]);
$credentials = $request->only('email', 'password');
if ( $token = JWTAuth::attempt($credentials) )
...