Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • encode password before saving it to database

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 203
    Comment on it

    Hello Readers. Here is small code to encode password before it is saved into database.

    Add the following code in your Model file User.php

    App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
    
    class User extends AppModel {
    	
        public $name = 'User';
        public function beforeSave($options = array())
        {
            if (isset($this->data[$this->alias]['password'])) {
                $passwordHasher = new BlowfishPasswordHasher();
                $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
            }
            return true;
        }
    }

    OUTPUT:

    encode password before saving it to 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: