title: CakePHP 2x Auth->login
body: <p>I just can't login with $this->Auth->login() function ... I follow some tutorial and do everything but when I submit the form it shows password and username error .. although I check the password it's encrypted and match the database password...</p>
  
  <p>any Ideas?? ...
  thanks in advance</p>
  
  <h1>this is my UsersController</h1>
  
  <pre><code>    &lt;?php
  
      App::uses('AppController', 'Controller');
  
      class UsersController extends AppController {
  
          public $components = array('Paginator');
  
          public function beforeFilter() {
               parent::beforeFilter(); 
               $this-&gt;Auth-&gt;allow('add');
               $this-&gt;Auth-&gt;deny('index');
          }
          public function login() {
              if($this-&gt;Session-&gt;read('Auth.User')){
                  $this-&gt;redirect($this-&gt;Auth-&gt;redirect());
              }
              if ($this-&gt;request-&gt;is('post')) {
                  print_r($this-&gt;request-&gt;data['User']['password']);
                  $encPassword = AuthComponent::password($this-&gt;request-&gt;data['User']['password']);
                  $this-&gt;request-&gt;data['User']['password'] = $encPassword;
                  print_r($this-&gt;request-&gt;data['User']['password'].' - '.$this-&gt;request-&gt;data['User']['username']);
                  //print_r($_SESSION);
                  if ($this-&gt;Auth-&gt;login()) {
                      return $this-&gt;redirect($this-&gt;Auth-&gt;redirect());
                  }
                  $this-&gt;Session-&gt;setFlash(__('Invalid username or password, try again'));
              }
          }
  
          public function logout() {
              return $this-&gt;redirect($this-&gt;Auth-&gt;logout());
          }
  
         public function add() {
              if ($this-&gt;request-&gt;is('post')) {
                  $this-&gt;User-&gt;create();
                  if ($this-&gt;User-&gt;save($this-&gt;request-&gt;data)) {
                      $this-&gt;Session-&gt;setFlash(__('The user has been saved'));
                      return $this-&gt;redirect(array('controller' =&gt; 'pages','action' =&gt; 'home'));
                  }
                  $this-&gt;Session-&gt;setFlash(__('The user could not be saved. Please, try again.'));
              }
          }
  
          public function index() {
              $this-&gt;User-&gt;recursive = 0;
              $this-&gt;set('users', $this-&gt;Paginator-&gt;paginate());
          }
  
          public function view($id = null) {
              if (!$this-&gt;User-&gt;exists($id)) {
                  throw new NotFoundException(__('Invalid user'));
              }
              $options = array('conditions' =&gt; array('User.' . $this-&gt;User-&gt;primaryKey =&gt; $id));
              $this-&gt;set('user', $this-&gt;User-&gt;find('first', $options));
          }
  
          public function edit($id = null) {
              if (!$this-&gt;User-&gt;exists($id)) {
                  throw new NotFoundException(__('Invalid user'));
              }
              if ($this-&gt;request-&gt;is(array('post', 'put'))) {
                  if ($this-&gt;User-&gt;save($this-&gt;request-&gt;data)) {
                      $this-&gt;Session-&gt;setFlash(__('The user has been saved.'));
                      return $this-&gt;redirect(array('action' =&gt; 'index'));
                  } else {
                      $this-&gt;Session-&gt;setFlash(__('The user could not be saved. Please, try again.'));
                  }
              } else {
                  $options = array('conditions' =&gt; array('User.' . $this-&gt;User-&gt;primaryKey =&gt; $id));
                  $this-&gt;request-&gt;data = $this-&gt;User-&gt;find('first', $options);
              }
          }
  
          public function delete($id = null) {
              $this-&gt;User-&gt;id = $id;
              if (!$this-&gt;User-&gt;exists()) {
                  throw new NotFoundException(__('Invalid user'));
              }
              $this-&gt;request-&gt;allowMethod('post', 'delete');
              if ($this-&gt;User-&gt;delete()) {
                  $this-&gt;Session-&gt;setFlash(__('The user has been deleted.'));
              } else {
                  $this-&gt;Session-&gt;setFlash(__('The user could not be deleted. Please, try again.'));
              }
              return $this-&gt;redirect(array('action' =&gt; 'index'));
          }
      }
  
  ?&gt;
  </code></pre>
  
  <h1>and this my User model</h1>
  
  <pre><code>&lt;?php
  
      App::uses('AppModel', 'Model');
  
      class User extends AppModel {
          public $validate = array(
              'username' =&gt; array(
                  'required' =&gt; array(
                      'rule' =&gt; array('notEmpty'),
                      'message' =&gt; 'A username is required'
                  )
              ),
              'password' =&gt; array(
                  'required' =&gt; array(
                      'rule' =&gt; array('notEmpty'),
                      'message' =&gt; 'A password is required'
                  )
              )
          );
  
          public function beforeSave($options = array()) {  
              if (isset($this-&gt;data[$this-&gt;alias]['password'])) {
                  $this-&gt;data[$this-&gt;alias]['password'] = AuthComponent::password($this-&gt;data[$this-&gt;alias]['password']);
              }
              return true;
          }
      }
  
  ?&gt;
  </code></pre>
  
  <h1>this my AppController</h1>
  
  <pre><code>&lt;?php
  
  App::uses('Controller', 'Controller');
  
  class AppController extends Controller {
  
      public $helpers = array('Seo');
  
      public $components = array(
          'Session',
          'Auth' =&gt; array(
              'loginRedirect' =&gt; array('controller' =&gt; 'users', 'action' =&gt; 'index'),
              'logoutRedirect' =&gt; array('controller' =&gt; 'pages', 'action' =&gt; 'home')
          ),
          'Do',
          'Images'
      );
  
      public function beforeFilter() {
          $this-&gt;Auth-&gt;allow('index', 'display', 'view');
      }
  
  }
  </code></pre>
  
  <h1>this my login forms page</h1>
  
  <pre><code>&lt;div&gt;
  &lt;header&gt;&lt;?php echo __('usersaccessform');?&gt;&lt;/header&gt;
  &lt;?php 
      echo $this-&gt;Form-&gt;create('User');
      echo $this-&gt;Form-&gt;input('User.username',array('type'=&gt;'text'));
      echo $this-&gt;Form-&gt;input('User.password',array('type'=&gt;'password'));
      echo $this-&gt;Form-&gt;end(__('submit'));
  ?&gt;
  &lt;/div&gt;
  </code></pre>