Search code examples
cakephpcakephp-2.4blowfish

Blowfish authentication in cakephp 2.4.2


Can anybody help me with cakephp 2.4.2 auth using blowfish, I'm new to cakephp auth so I've googled it up but didn't find any solution for my problem.

Here is my code

For App Controller

public $components = array(
    'Session',
    'RequestHandler',
    'Auth' => array(
        'authenticate' => array(
            'Form' => array(
                'passwordHasher' => 'Blowfish'
            )
        )
    )
);

For Model

        public function beforeSave($options = array()){
        if (isset($this->data[$this->name]['password'])) {
            $this->data[$this->name]['password'] = Security::hash($this->data[$this->alias]['password'], 'blowfish');
        }
        return true;
    }

For Controller

                if ($this->Auth->login()) {
                    $this->redirect(array('controller' => 'admins', 'action' => 'dashboard', 'builder' => true));
                } else {
                    $this->Session->write('flash', array('You Have entered wrong username or password.', 'failure'));
                    $this->redirect(array('controller' => 'users', 'action' => 'login', 'builder' => true));
                }

Solution

  • Try this in your AppController:

    $this->Auth->authenticate = array(
            AuthComponent::ALL => array(
                'userModel' => 'User',
                'fields' => array(
                    'username' => 'email',
                    'password' => 'password'
                ),
                'scope' => $user_scope,
            ), 'Form'=> array(
                    'passwordHasher' => 'Blowfish'
                )
        );