Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Login with Auth driver, but without password

Okay, so to keep it simple I have a users table, and a User model. The table contains a unique identifier com_id (plus other user info), which I'd like to login with, but no password.

I'd like to log the user in, and be able to access their data via the Auth driver: Auth::user()->email etc, but I'm having some problems logging them in.

if (Auth::attempt(['com_id' => $com_id]))
{
   dd("successful login");
}

With this, I get an error regarding the UserInterface, so in my Model I add:

use Illuminate\Auth\UserInterface;

class User extends Eloquent implements UserInterface {

    protected $table = 'users';

    protected $guarded = array('id');

    public function getAuthIdentifier()
    {
        return $this->steam_community_id;
    }

    public function getAuthPassword()
    {
        return $this->password;
    }
}

But what do I do about the password? I can't remove the function since it's required, and I'm not sure what the getAuthIdentifier is supposed to refer to?

Any help would be nice.

I could handle this through Sessions, but surely this is possible the "normal" way.

like image 410
Alias Avatar asked Feb 12 '14 22:02

Alias


1 Answers

To log in user without a password in Laravel 4. You just need to call method login.

Auth::login($user);

This method will log in your user without any credential check.

If you need to check the credentials in other hand, this method which will check the credentials.

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

like image 197
Djuki Avatar answered Sep 29 '22 18:09

Djuki