title: CakeDC Users login with username
body: <p>The default login process requires e-mail, not username.</p>
  
  <p>I've added this to <code>AppController.php</code> on <code>beforeFilter()</code>, which is also mentioned on <a href="http://book.cakephp.org/1.3/en/The-Manual/Core-Components/Authentication.html" rel="nofollow">CakePHP's Docs Authentication</a>:</p>
  
  <pre><code>$this-&gt;Auth-&gt;fields = array(
      'username' =&gt; 'username',
      'password' =&gt; 'password'
  );
  </code></pre>
  
  <p>But somehow it does not allow users to login with their usernames. Any ideas on how I can change that?</p>
  
  <p><strong>AppController</strong></p>
  
  <pre><code>App::uses('Controller', 'Controller');
  class AppController extends Controller {
  var $components = array(
      'Session',
      'RequestHandler',
      'Security'
  );
  var $helpers = array('Form', 'Html', 'Session', 'Js');
  
  public function beforeFilter() {
      $this-&gt;Auth-&gt;authorize = 'Controller';
      $this-&gt;Auth-&gt;fields = array('username' =&gt; 'username', 'password' =&gt; 'password');
      $this-&gt;Auth-&gt;loginAction = array('plugin' =&gt; 'users', 'controller' =&gt; 'users', 'action' =&gt; 'login', 'admin' =&gt; false);
      $this-&gt;Auth-&gt;loginRedirect = '/';
      $this-&gt;Auth-&gt;logoutRedirect = '/';
      $this-&gt;Auth-&gt;authError = __('Sorry, but you need to login to access this location.', true);
      $this-&gt;Auth-&gt;loginError = __('Invalid e-mail / password combination.  Please try again', true);
      $this-&gt;Auth-&gt;autoRedirect = true;
      $this-&gt;Auth-&gt;userModel = 'User';
      $this-&gt;Auth-&gt;userScope = array('User.active' =&gt; 1);  
      if ($this-&gt;Auth-&gt;user()) {
          $this-&gt;set('userData', $this-&gt;Auth-&gt;user());
          $this-&gt;set('isAuthorized', ($this-&gt;Auth-&gt;user('id') != ''));
      }
  }
  </code></pre>
  
  <p><strong>/View/Users/login.ctp</strong></p>
  
  <p>This is the same as the default <code>login.ctp</code> found in the plugin's folder. I just changed the field email to username.</p>
  
  <p>Now, here is something interesting. Regardless the code I put in this file, CakePHP pulls the content from the plugin login view, the view I created is ignored.</p>
  
  <p><strong>Debugging</strong></p>
  
  <p>When calling the debugger:</p>
  
  <pre><code>Debugger::dump($this-&gt;Auth);
  </code></pre>
  
  <p>It shows all the values that I set. But it still does not accept the username. I can still login with email, so it is not that I am inserting the wrong credentials. It is just that it is waiting for email/password, not username/password.</p>