0

The Auth is returning false. Hashed password matches the hashed password in database, but still returns false.

Here is the model:

    App::uses('AppModel', 'Model');

    class User extends AppModel {

     public $validate = array(
    'username' => array(
        'notEmpty' => array(
            'rule' => array('notEmpty'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
         ),
         'password' => array(
          'notEmpty' => array(
            'rule' => array('notEmpty'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
        ),
        );
       public function beforeSave($options = array()) {
    if (isset($this->data[$this->alias]['password'])) {

        $this->data[$this->alias]['password'] =AuthComponent::password($this->data[$this->alias]['password']);

        ;
    }
    return true;



}
      }

Here is the AppController:

     class AppController extends Controller {


      public $components = array(
      'Session',
       'Auth' => array(
        'authenticate' => array(
            'Form' => array(

            )
        ),
        'loginAction'=>array(
            'controller'=>'users',
            'action'=>'login'
        ),
        'loginRedirect' => array(
            'controller' => 'references',
            'action' => 'admin_index'
        ),
        'logoutRedirect' => array(
            'controller' => 'home',
            'action' => 'index',
            'home'
        )

      )
     );
     public function beforeFilter() {
    $this->Auth->allow('index', 'view');
    }

     }

Here is the UsersController:

         public function login(){

        var_dump($this->Auth->login());die;
        if ($this->request->is('post')) {
        if ($this->Auth->login()) {

            return $this->redirect(array('controller'=>'references',   'action'=>'admin_index'));

        }

        $this->Session->setFlash(__('Invalid username or password, try again'));
         }
       }

And the view :

           <div class="users form">
         <?php echo $this->Session->flash('auth'); ?>
         <?php echo $this->Form->create('User',array('action'=>'login')); ?>
          <fieldset>
        <legend>
        <?php echo __('Please enter your username and password'); ?>
       </legend>
       <?php echo $this->Form->input('username');
       echo $this->Form->input('password');
      ?>
      </fieldset>
       <?php echo $this->Form->end(__('Login')); ?>
       </div>

I have tried using BlowFish but its not working, so I switched to Auth default hashing and the hashes when creating user and then loging in match so the hashing is working fine. I dont get what the problem is, so please help.

user1915462
  • 13
  • 2
  • 6

1 Answers1

0

after a half an hour i tried again and now its working. Who knows what was the problem. Anyway, thanks for reading and post answers if you find any issue in code above. Thanks!

user1915462
  • 13
  • 2
  • 6