Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use Blowfish password hasher in cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 323
    Comment on it

    Hellow Reader's ,

    In this Blog you can learn how to secure your password in DB with Blowfish password hasher. it is very difficult to hack. you can use blowfish hasher by following these steps.

    First use below line in your User (Model)

    App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');

    Then add this in model

    public function beforeSave($options = array()) {
            // hash the user's password before we save it
            if (isset($this->data[$this->alias]['password'])) {
                $passwordHasher = new BlowfishPasswordHasher();
                $this->data[$this->alias]['password'] = $passwordHasher->hash(
                    $this->data[$this->alias]['password']
                );
            }
              
            // fallback to our parent
            return parent::beforeSave($options);
        }

    It will hash your password before save record in Database

    and for use blowfish hash password add this in auth component (AppController)

     

    public $components = array('Session', 'Cookie',
        'Auth' => array(
    
                    'authenticate' => array(
                        'Form' => array(
                                'passwordHasher' => 'Blowfish',
                                'userModel' => 'User',
                                'fields' => array(
                                'username' => 'username',
                                'password' => 'password'
                            )
                        )
                    )
    
        ),
    );

    Please feel free to comment.

 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: