CakePHP 2:4 : Authcomponent not working

480 views Asked by At

There I have two tables

1) aucusers 2) user_types

For use auth component I used bellow code in appcontroller

public $components = array('Session','RequestHandler','Paginator'=>array('limit'=>4),'Auth'=>array(
    'loginAction' => array(
        'controller' => 'aucusers',
        'action' => 'login'
    ),
        'loginRedirect' => array('controller' => 'aucusers','action' => 'add'),
        'logoutRedirect' => array('controller' => 'aucusers','action' => 'add'),
        'authError'=>'You can not access this page!!',
    ));



public function beforeFilter() {

    $this->set('logged_in', $this->Auth->loggedIn());
    $this->set('current_user',$this->Auth->user());
     parent::beforeFilter();
        $this->Paginator->settings = array(
          'limit'=>4
    );

In model for Hash password I have used

     public function beforeSave($options = array()) {
        if (isset($this->data[$this->alias]['password'])) {
            $passwordHasher = new SimplePasswordHasher();
            $this->data[$this->alias]['password'] = $passwordHasher->hash(
                $this->data[$this->alias]['password']
            );
        }
        return true;
    }

In aucusers controller I have add

public function login() {

    if ($this->request->is('post')) {
        if ($this->Auth->login()) {
            return $this->redirect($this->Auth->redirect());
        }
        $this->Session->setFlash(__('Invalid username or password, try again'));
    }
}

    public function logout() {
        return $this->redirect($this->Auth->logout());
    }

After add

$this->Auth->allow()

I have made a user.But when I am going to login, it showing me

Invalid username or password, try again.

1

There are 1 answers

0
Nizam On

As far as I know, you have to define which hashing method you are using.

From http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

public $components = array(
    'Auth' => array(
        'authenticate' => array(
            'Form' => array(
                'passwordHasher' => array(
                    'className' => 'Simple',
                    'hashType' => 'sha256'
                )
            )
        )
    )
);