php - Hashing password before saving to databse in yii -


i using yii framework building small application of job site.and have encounterd errors mentioned below

my controller class follow:

  public function actionregister() {         $model = new registerform();     if (isset($_post['registerform'])) {          //  print_r($_post); exit();          $model->attributes = $_post['registerform'];         if ($model->validate()) {             $model->password = sha1($model['password']);             $model->role ='user';             $model->status='1';             $model->created =date("y-m-d h:i:s");             $model->modified =date("y-m-d h:i:s");              if ($model->save()) {                  yii::app()->user->setflash('success', "data saved!");             } else {                  yii::app()->user->setflash('error', "error,cannot save data!");             }         } else {             yii::app()->user->setflash('error', "validation failed!");         }     }     $this->render('register', array('model' => $model)); } 

and rules validation as:

public function rules()     {                return array(             // fields required  //             array('username, password,contact,email,name','required'),                         array('email','email'),                         array('contact', 'match', 'pattern'=>'/^[0-9]{1,15}$/'),                         array('email','validateemail'),                         array('repassword', 'compare', 'compareattribute'=>'password' ,'message'=>"passwords don't match")                      // password needs authenticated             /*array('password', 'authenticate'),*/         );     } 

i encountering error while submiting data,perhaps due confirm password prompting error password did not match type same value in both fields.

use

$model->save(false); // save no validation 

because have validated model directly before


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -