1
votes

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

    }

});
3
Do you have a unaltered User model? Also tell us what you have in your table. On a side note, is the password in your table hashed as the Auth hashes the password before querying. - fl3x7
@fl3x7 I'm in a similar situation as well. Can you elaborate your side note. that might be solution to the problem. thanks - Junaid Qadir Shekhanzai
@JeyKeu More details on hashing at: laravel.com/docs/security#storing-passwords - fl3x7

3 Answers

1
votes

change

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

to

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

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.

0
votes

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.