title: Laravel 4 authentication with email and ID
body: <p>Basically I want to allow users to log in using their email address and password, but use an auto-incrementing ID as the Users table primary key.</p>
  
  <p><a href="http://www.codediesel.com/frameworks/simple-user-authentication-in-laravel-4/" rel="nofollow">Some tutorials</a> seem to indicate this is very straight forward. But that doesn't seem to be working for me. For a start I've had to alter the User model to use "email" as the authentication identifier. This works, but sessions do not save (see below).</p>
  
  <p>Users table migration file;</p>
  
  <pre><code>Schema::create("users", function ($table) {
    $table-&gt;increments("id");
    $table-&gt;string("email", 255)-&gt;unique();
    $table-&gt;string("password", 60);
    $table-&gt;timestamps();
  });
  </code></pre>
  
  <p>User model file;</p>
  
  <pre><code>use Illuminate\Auth\UserInterface;
  use Illuminate\Auth\Reminders\RemindableInterface;
  
  class User extends Eloquent implements UserInterface, RemindableInterface {
    protected $table = 'users';
    protected $hidden = array('password');
  
    public function getAuthIdentifier() {
      return $this-&gt;email;
    }
  
    public function getAuthPassword() {
      return $this-&gt;password;
    }
  
    public function getReminderEmail() {
      return $this-&gt;email;
    }
  }
  </code></pre>
  
  <p>Logging in with;</p>
  
  <pre><code>Auth::attempt(array("email" =&gt; Input::get("email"), "password" =&gt; Input::get("password")), true);
  </code></pre>
  
  <p>...works (as in returns true). The session however does not save properly. Any subsequent requests aren't authenticated. I've tried different session drivers with no success.</p>
  
  <p>If I add;</p>
  
  <pre><code>protected $primaryKey = "email";
  </code></pre>
  
  <p>to the User model, the sessions work. <strong>But</strong> that can't be right, as "email" is not that table's primary key, "id" is (and I would like to keep "id" as the primary key).</p>
  
  <hr>
  
  <p><strong>Also:</strong> The <a href="http://laravel.com/docs/security" rel="nofollow">official documentation</a> seems to indicate that you don't have to do <em>anything</em> special to use "email" as the identifying column, as "email" is used <a href="http://laravel.com/docs/security#authenticating-users" rel="nofollow">here</a>, but then the numeric ID is used <a href="http://laravel.com/docs/security#manually" rel="nofollow">here</a>. Am I missing something obvious here?</p>