title: Cakephp 2.1- login system using AuthComponent
body: <p>I am going crazy with a problem for days now. I used the documentation and videos on youtube. Also some tutorials only about that particular issue. But there is something wrong that i can't see. I nedd a login system in a web system using cakephp.
   My table of users is the following:</p>
  
  <pre><code>    CREATE TABLE `usuarios` (
      `Id` INT(50) UNSIGNED NOT NULL AUTO_INCREMENT,
      `grupo_id` INT(50) UNSIGNED NOT NULL,
      `Status` VARCHAR(30) NOT NULL COMMENT 'Coordenador/Bolsista/Super',
      `Nome` VARCHAR(50) NOT NULL,
      `Login` VARCHAR(50) NOT NULL,
      `Email` VARCHAR(50) NOT NULL,
      `Senha` VARCHAR(50) NOT NULL,
      `created` DATETIME NULL DEFAULT NULL,
      `modified` DATETIME NULL DEFAULT NULL,
      PRIMARY KEY (`Id`),
      UNIQUE INDEX `Login` (`Login`),
      UNIQUE INDEX `Nome` (`Nome`),
      INDEX `FK_usuarios_grupos` (`grupo_id`),
      CONSTRAINT `FK_usuarios_grupos` FOREIGN KEY (`grupo_id`) REFERENCES `grupos` (`Id`) ON UPDATE CASCADE
  )
  COLLATE='latin1_swedish_ci'
  ENGINE=InnoDB
  AUTO_INCREMENT=8;
  </code></pre>
  
  <p>Where Status is the level of authorization for differente parts os the system. the 3 options are described in comments. </p>
  
  <pre><code>In my AppController, after some time, I coded:
  
      class AppController extends Controller {
      public $components = array('Session',
                                 'Auth'=&gt;array(
                                            'authenticate' =&gt; array(
                              'Form' =&gt; array(
                                             'fields'=&gt;array(
                                                             'username'=&gt;'Login',
                                                             'password'=&gt;'Senha'
                                                              ),
                                      'userModel'=&gt; 'Usuario'
                              ),
                             ),
                             'loginAction' =&gt;array(
                                                      'Controller' =&gt; 'Usuarios',
                                                      'action' =&gt; 'login'
                                             ),
                  'loginRedirect'=&gt;array('Controller'=&gt;'Usuarios', 'action'=&gt;'index'), 
                  'logoutRedirect'=&gt;array('Controller'=&gt;'Usuarios', 'action'=&gt;'index'), 
                  'authError'=&gt;"You can't access that page", 
                  'authorize'=&gt;'Controller', 
                  'loginError'=&gt; 'Login errado'
  
              )
      );
  
      public function isAuthorized($usuario=null) {
          //return parent::isAuthorized($usuario);
          return true;
      }
  
      public function beforeFilter() {
          $this-&gt;Auth-&gt;allow('index','view');
          $this-&gt;set('logged_in', $this-&gt;Auth-&gt;loggedIn());
          $this-&gt;set('current_user', $this-&gt;Auth-&gt;user());
      }
      }?&gt;
  </code></pre>
  
  <p>The isAuthorized method has two options because i was trying things... The main problem is, every time i try to log in i go to the AuthError message. No matter if is a registered (with hashed password) or an invalid one. I do not see why this happens, but i suspect it is a issue with isAutorized method.</p>
  
  <p>My specif controller has the following relevent methods:</p>
  
  <pre><code>public function login() {
          if ($this-&gt;request-&gt;is('post')) {
              if ($this-&gt;Auth-&gt;login()) {
                  return $this-&gt;redirect($this-&gt;Auth-&gt;redirect());   
              } else {
                  $this-&gt;Session-&gt;setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
                  $this-&gt;Session-&gt;setFlash('Username or password is incorrect');
  
              }
          }
      }
  
      public function logout() {
          $this-&gt;redirect($this-&gt;Auth-&gt;logout());
      }   
      public function beforeFilter() {
          parent::beforeFilter();
          $this-&gt;Auth-&gt;allow('add_bolsista','logout');
      }
  
      public function isAuthorized($usuario = null) {
          if (($usuario['Status'] == 'Super') || ($usuario['Status'] == 'Coordenador') || ($usuario['Status'] == 'Bolsista')) {
              return true;
          }
          if (in_array($this-&gt;action, array('edit', 'delete'))) {
              if ($usuario['Id'] != $this-&gt;request-&gt;params['pass'][0]) {
                  return false;
              }
          }
          return true;
      }
  
      public function isAuthorized($usuario = null) {
      // Any registered user can access public functions
      if (empty($this-&gt;request-&gt;params['Bolsista'])) {
          return true;
      }
  
      // Only admins can access admin functions
      if (isset($this-&gt;request-&gt;params['Super'])) {
          return (bool)($usuario['Status'] === 'Super');
      }
  
      // Default deny
      return false;
  }
  </code></pre>
  
  <p>Two version of the isAuthorized...none seems to really work.
  Anyone??</p>