2013-02-11 139 views
1

无法设法登录任何人的想法?我仍然得到重定向到登录页面用户登录laravel 4

Route::post('login', function() { 
    // get POST data 
    $email = Input::get('username'); 
    $password = Input::get('password'); 
    if (Auth::attempt(array('email' => $email,'password' => $password))) 
    { 

     return Redirect::to('home'); 
    } 
    else 
    { 
     // auth failure! lets go back to the login 
     return Redirect::to('login') 
      ->with('login_errors', true); 

    } 

}); 
+0

你有没有改变的用户模型?同时告诉我们你的桌子上有什么。请注意,在查询之前,您的表中的密码是否由于Auth散列密码而散列。 – fl3x7 2013-03-07 18:17:01

+0

@ fl3x7我也处于类似的情况。你能否详细说明你的附注。这可能是解决问题的方法。谢谢 – 2014-03-09 22:21:41

+0

@JeyKeu有关哈希的更多详细信息,请参见:http://laravel.com/docs/security#storing-passwords – fl3x7 2014-03-11 12:57:02

回答

1

变化

if (Auth::attempt(array('email' => $email,'password' => $password))) 

if (Auth::attempt(array('username' => $email,'password' => $password))) 
+0

根据[documentation](http://laravel.com/docs/security#authenticating-用户) – 2014-03-09 22:12:49

+0

这取决于。您应该在数据库中使用与“用户名”相对应的任何列名称。 – Laurence 2014-03-10 06:43:57

0

Laravel有一个设置,让你指定的用户名的是“用户名”或“电子邮件'(或其他您可能选择的),请检查配置。如上所示...

if (Auth::attempt(array('username' => $email,'password' => $password))) 

此外,Laravel预计默认情况下哈希密码。

0

要使用电子邮件用户名,尝试添加这对用户模式:

protected $primaryKey = 'email'; 

另外,还要确保电子邮件是你的“用户”表的主键。