user login laravel 4

拜拜、爱过 提交于 2019-12-11 06:07:34

问题


can't manage to login anybody an idea? i still get redirected back to the login page

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);

    }

});

回答1:


change

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

to

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



回答2:


Laravel has a setting that lets you specify the username as either 'username' or 'email' (or whatever else you may choose), check config. Like above indicated...

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

Also, Laravel expects a hashed password by default.




回答3:


To use email as username, try adding this to User model:

protected $primaryKey = 'email';

Also make sure email is the primary key on your 'user' table.



来源:https://stackoverflow.com/questions/14814526/user-login-laravel-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!