Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • cakephp 2.4.2: How to do Blowfish authentication

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 231
    Comment on it

    What is Blowfish Authentication:

    It is an authentication adapter for AuthComponent. Blowfish is a symmetric-key block cipher. It provides the ability to authenticate Post Data using Blow Fishing. In order to add Blow fish authentication add it in Auth Component via AuthComponent::$authenticate settings.

    Follow the steps below to add authentication using BlowFish.

    Step1: In App Controller write following lines of code:

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

     

    Step2: In Model write the following function:

       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;
        }

    Step 3: In Controller write following code:

      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));
     }

     

    Now run the web page, its all done!. You will see that password is encrypted in database.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: