I have been developing an application in Yii framework. I create a registration form where there is a field that is password. After registration, I saw that password result stored in db is being encrypted twice of md5.
I wrote in model as:
protected function afterValidate()
{
$this->password = $this->encrypt($this->password);
}
public function encrypt($value)
{
return md5($value);
}
an in controller
public function actionRegistration()
{
$model=new User('registration');
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
$model->scenario = 'registerwcaptcha';
if(isset($_POST['User']) )
{
$model->attributes=$_POST['User'];
$keystring = md5( rand(0,1000) ); // Generate random 32 character hash and assign it to a local variable.
$model->keystring = $keystring;
//$model->password = md5( $model->password );
if($model->validate())
{
// and here is the actual HACKY part
$model->scenario = NULL;
// save user registration
if($model->save())
$this->redirect(array('emailverify'));
}
}
$this->render('registration',array(
'model'=>$model,
));
}
Could anybody help me please.
The latest version of Yii has password hashing build in.
To hash you can use:
$hash = CPasswordHelper::hashPassword($password);
and to verify:
For more detailed information take a look at this page:
http://www.yiiframework.com/doc/api/1.1/CPasswordHelper/