title: CakePHP Changing Auth Fields isn't working
body: <p>I'm currently trying to change my cakephp login from using the username field to using the email field.</p>
  
  <p>When using the username field, the login works fine, here's the code for the login with username:</p>
  
  <p>login.ctp</p>
  
  <pre><code>&lt;?php
  echo $this-&gt;Form-&gt;create('User');
  echo $this-&gt;Form-&gt;input('username');
  echo $this-&gt;Form-&gt;input('password');
  echo $this-&gt;Form-&gt;end(__('Login'));
  ?&gt;
  </code></pre>
  
  <p>UsersController.php</p>
  
  <pre><code>public function beforeFilter() {
      parent::beforeFilter();
      $this-&gt;Auth-&gt;allow('add', 'login'); // Letting users register themselves
      $this-&gt;Auth-&gt;fields = array('username' =&gt; 'username', 'password' =&gt; 'password');
  }
  public function login() {
      if ($this-&gt;request-&gt;is('post')) {
          if ($this-&gt;Auth-&gt;login()) {
              $this-&gt;Session-&gt;setFlash(__('worked'));
          } else {
              debug($this-&gt;data);
              $this-&gt;Session-&gt;setFlash(__('Invalid username or password, try again'));
          }
      }
  }
  </code></pre>
  
  <p>AppController</p>
  
  <pre><code>public $components = array('Session', 'Auth');
  </code></pre>
  
  <p>So this all works fine, I can login with test details.</p>
  
  <p>So to change this to using an email, all I have done is:</p>
  
  <ul>
  <li><p>Change the input in login.ctp from username to email</p>
  
  <pre><code>echo $this-&gt;Form-&gt;input('email');
  </code></pre></li>
  <li><p>Change the fields array in userscontroller from username to email</p>
  
  <pre><code>$this-&gt;Auth-&gt;fields = array('username' =&gt; 'email', 'password' =&gt; 'password');
  </code></pre></li>
  <li><p>Change the database field from username to email</p></li>
  </ul>
  
  <p>I then try to login using the same test details and it tells me they are incorrect.</p>
  
  <p>Does anyone have any idea why this wouldn't work?</p>