title: login code in cakephp 2.7 using auth component
body: <p>I am using cakephp 2.7.8</p>
  
  <p>Tablename - <strong>users</strong></p>
  
  <p><strong>fields in table</strong></p>
  
  <p>id
  name
  email
  password</p>
  
  <p>i am trying to login and if login is succesful then it redirects to ad page.</p>
  
  <p>but i dont now why</p>
  
  <p><strong>My login shows error after form submit</strong></p>
  
  <p><strong>Invalid username and password.</strong></p>
  
  <p>but my table contain the exact value available.</p>
  
  <p>plz help me find out error.</p>
  
  <p>controller file name -  UsersController.php</p>
  
  <pre><code>&lt;?php
  class UsersController extends AppController {   
  
        public $helpers = array('Form', 'Html');
        public $components = array('Flash');
  
       public function beforeFilter() 
       {
          parent::beforeFilter();     
          $this-&gt;Auth-&gt;allow('add');
       }
  
       public function login() {
         if ($this-&gt;request-&gt;is('post')) {
                  //print_r($this-&gt;request-&gt;is('post'));
                  //exit;
                  if ($this-&gt;Auth-&gt;login()) {
                      return $this-&gt;redirect($this-&gt;Auth-&gt;redirect(array('controller' =&gt; 'Users', 'action' =&gt; 'add')));
                  }
                  $this-&gt;Flash-&gt;error(__('Invalid username or password, try again'));
              }
          }
  }
  ?&gt;
  </code></pre>
  
  <p>Model file name - User.php</p>
  
  <pre><code>&lt;?php
  
  class User extends AppModel {
  
  public $validate = array('lname' =&gt; array('rule' =&gt; 'notEmpty'));
  
  }
  ?&gt;
  </code></pre>
  
  <p>login.ctp</p>
  
  <pre><code>&lt;?php 
  echo $this-&gt;form-&gt;create('User', array('action' =&gt; 'login'));
  echo $this-&gt;form-&gt;input('email');
  echo $this-&gt;form-&gt;input('password');
  echo $this-&gt;form-&gt;end('login');
  ?&gt;
  </code></pre>
  
  <p><strong>Appcontroller.php</strong></p>
  
  <pre><code>&lt;?php
  App::uses('Controller', 'Controller');
  
  class AppController extends Controller {
  
       public $components = array(
          'Flash',
          'Auth' =&gt; array(
              'loginRedirect' =&gt; array(
                  'controller' =&gt; 'Users',
                  'action' =&gt; 'index'
              ),
              'logoutRedirect' =&gt; array(
                  'controller' =&gt; 'Users',
                  'action' =&gt; 'display',
                  'home'
              )
          )
      );
  
      public function beforeFilter() {
          $this-&gt;Auth-&gt;allow('index', 'view','update','delete');
      }
  
  
  }
  ?&gt;
  </code></pre>