Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.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
Php Laravel身份验证尝试失败_Php_Authentication_Login_Laravel - Fatal编程技术网

Php Laravel身份验证尝试失败

Php Laravel身份验证尝试失败,php,authentication,login,laravel,Php,Authentication,Login,Laravel,在我把我的问题带到这里之前,我真的试图自己调试我的问题,但是我真的找不到解决我的laravel auth问题的方法,尽管这似乎是一个常见的问题 我的身份验证将不会登录。它总是返回false,我不明白为什么 我已经通读了其他一些问题,他们的解决方案并没有解决我的特殊情况 我的用户模型实现了用户界面和可提醒界面 我的密码在创建到数据库时会被散列 我的数据库中的密码字段是varchar 100,这应该足以散列密码 我正在记录的用户已在数据库中创建并激活 非常感谢您的见解 用户模型 路线 您的代码在

在我把我的问题带到这里之前,我真的试图自己调试我的问题,但是我真的找不到解决我的laravel auth问题的方法,尽管这似乎是一个常见的问题

我的身份验证将不会登录。它总是返回false,我不明白为什么

我已经通读了其他一些问题,他们的解决方案并没有解决我的特殊情况

  • 我的用户模型实现了用户界面和可提醒界面
  • 我的密码在创建到数据库时会被散列
  • 我的数据库中的密码字段是varchar 100,这应该足以散列密码
  • 我正在记录的用户已在数据库中创建并激活
非常感谢您的见解

用户模型

路线


您的代码在我看来是正确的,因此您必须检查以下内容:

1) 手动尝试对你有用吗

dd( Auth::attempt(['email' => 'youremail', 'password' => 'passw0rt']) );
2) 用户是否手动进行哈希检查

$user = User::find(1);

var_dump( Hash::check($user->password, 'passw0rt') );

dd( Hash::check($user->password, Input::get('password')) );

您的代码在我看来是正确的,因此您必须检查以下内容:

1) 手动尝试对你有用吗

dd( Auth::attempt(['email' => 'youremail', 'password' => 'passw0rt']) );
2) 用户是否手动进行哈希检查

$user = User::find(1);

var_dump( Hash::check($user->password, 'passw0rt') );

dd( Hash::check($user->password, Input::get('password')) );

在创建您已完成的用户时

$password = Input::get('email');
应该是

$password = Input::get('password');
因此,如果您尝试以“电子邮件”作为密码登录,它将起作用!:)

所以如果你改变这个

else {
        $email = Input::get('email');
        $username = Input::get('username');
        $password = Input::get('email');

        $code = str_random(60);

        $user = User::create(array(
            'email' => $email,
            'username' => $username,
            'password' => Hash::make($password),
            'code' => $code,
            'active' => 0));
});
对此

else {
        $user = User::create(array(
            'email' => Input::get('email'),
            'username' => Input::get('username'),
            'password' => Hash::make(Input::get('password');),
            'code' => str_random(60),
            'active' => 0));
});

这将清理您的代码并修复问题。

在创建您已完成的用户时

$password = Input::get('email');
应该是

$password = Input::get('password');
因此,如果您尝试以“电子邮件”作为密码登录,它将起作用!:)

所以如果你改变这个

else {
        $email = Input::get('email');
        $username = Input::get('username');
        $password = Input::get('email');

        $code = str_random(60);

        $user = User::create(array(
            'email' => $email,
            'username' => $username,
            'password' => Hash::make($password),
            'code' => $code,
            'active' => 0));
});
对此

else {
        $user = User::create(array(
            'email' => Input::get('email'),
            'username' => Input::get('username'),
            'password' => Hash::make(Input::get('password');),
            'code' => str_random(60),
            'active' => 0));
});

这将清理代码并修复问题。

尝试在用户模型中添加
primaryKey
字段。应该是这样的:

protected $primaryKey = 'user_id';

尝试在用户模型中添加
primaryKey
字段。应该是这样的:

protected $primaryKey = 'user_id';

我认为Apache版本有问题。您需要更新Apache2.4。

我认为Apache版本有问题。你需要更新Apache2.4。

哇,我犯了个愚蠢的错误!这绝对修复了一切!也感谢您的代码清理,我对这一点非常陌生,希望尽我所能学习!)哇,我犯了个愚蠢的错误!这绝对修复了一切!也感谢您的代码清理,我对这一点非常陌生,希望尽我所能学习!)应交换Hash::check()的参数。。它的哈希::check('passw0rt',$user->password);您写错了
Hash::check('plain-text',$hashedPassword)
Hash::check()的参数应该交换。。它的哈希::check('passw0rt',$user->password);您写错了
Hash::check('plain-text',$hashedPassword)