不工作Laravel 4认证 [英] Laravel 4 authentication not working

查看:130
本文介绍了不工作Laravel 4认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Laravel 4的应用程序中,我已经设置了一个用户。在我登录的路线我打电话验证::尝试通过电子邮件和密码,但它总是回来为假。我绝对有密码是否正确,并在数据库中作为正确的哈希散列::检查返回true。

我想这可能是由于使用电子邮件作为登录域而不是用户名,但我可以'看不到该任何设置。 这个问题意味着您可以添加一个选项,配置/ auth.php ,但没有奏效。 这个问题说,使用用户名作为数组键,但然后我得到SQL错误,因为它试图在数据库中的用户名字段中选择。

我需要的东西添加到用户模型,以指定的用户名外地?这是我的登录路径:

 路线::后('登陆',函数(){    //从登录表单数据
    $凭证=阵列(
        电子邮件=>输入::获得(电子邮件),
        '密码'=>输入::得到('密码')
    );    $ AUTH =哈希::检查(输入::得到('密码'),散列::让('为mypass'));
    后续代码var_dump($ AUTH); // 这是真的    //登录为好
    $ AUTH =验证::尝试($凭证);
    后续代码var_dump($ AUTH); //这是FALSE
});


解决方案

我发现这个问题。如上评论建议由Jason,我已经修改了模型/ user.php的文件,并删除,我不知道是必要的某些功能。

getAuthIdentifier() getAuthPassword()方法必须包括在用户模型进行验证!

I have a Laravel 4 app in which I have set up one user. In my login route I'm calling Auth::attempt with the email and password but it always comes back as false. I definitely have the password correct and the correct hash in the database as Hash::check returns true.

I think it may be due to using email as the login field instead of username, but I can't see any setting for that. This question implied you could add an option to config/auth.php but it didn't work. This question says to use username as the array key, but then I get SQL error because it tries to select on a username field in the database.

Do I need to add something to the User model to specify the username field? Here is my login route:

Route::post('login', function() {

    // data from login form
    $credentials = array(
        'email' => Input::get('email'),
        'password' => Input::get('password')
    );

    $auth = Hash::check(Input::get('password'), Hash::make('mypass'));
    var_dump($auth); // this is TRUE

    // login was good
    $auth = Auth::attempt($credentials);
    var_dump($auth); // this is FALSE
});

解决方案

I found the problem. As suggested by Jason in the comment above, I had modified the models/User.php file and removed some functions that I didn't realise were necessary.

The getAuthIdentifier() and getAuthPassword() methods must be included in the User model for authentication!

这篇关于不工作Laravel 4认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆