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
    • 281
    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:

    1. $this->Auth->authenticate = array(
    2. AuthComponent::ALL => array(
    3. 'userModel' => 'User',
    4. 'fields' => array(
    5. 'username' => 'email',
    6. 'password' => 'password'
    7. ),
    8. 'scope' => $user_scope,
    9. ), 'Form'=> array(
    10. 'passwordHasher' => 'Blowfish'
    11. )
    12. );

     

    Step2: In Model write the following function:

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

    Step 3: In Controller write following code:

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

     

    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
Reset Password
Fill out the form below and reset your password: