我有一个Laravel 4应用程序,我在其中设置了一个用户。在我的登录路线中,我使用电子邮件和密码拨打Auth::attempt
,但它总是返回为假。我确定密码正确并且数据库中的正确哈希值为Hash::check
返回true。Laravel 4身份验证不起作用
我认为这可能是由于使用email
作为登录字段而不是username
,但我看不到任何设置。 This question表示您可以将选项添加到config/auth.php
,但它不起作用。 This question表示使用username
作为数组键,但后来我得到SQL错误,因为它试图在数据库中的用户名字段上进行选择。
我是否需要向用户模型添加一些内容以指定用户名字段?这里是我的登录路线:
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
});
数组键应该与用于验证数据库中用户的列对应。这在[docs](http://four.laravel.com/docs/security#authenticating-users)中提到。你是否更改过L4附带的默认'User'模型? – 2013-04-24 01:00:22