I am learning yii framework by expanding the blog tutorial. To manage users, I created the UserController and User model. To generate encrypted password and salt, I modified the actionCreate() method of UserController as given here :
public function actionCreate()
{
$model=new User;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['User']))
{
// salt
srand(time()) ;
$randval = rand(0,time()); // generate a random number generator
$mdsalt = md5($randval) ;
$_POST['User']['salt'] = $mdsalt ;
$newpassword = md5($mdsalt .$_POST['User']['password'] ) ;
$_POST['User']['password'] =$newpassword;
//print_r($_POST['User']);
//return ;
$model->attributes=$_POST['User'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
Framework saves the new user record in tbl_user, however, the salt field in tbl_user is always NULL. If I print $_POST[‘User’], I do see data for salt, as shown here.
Array ( [username] => Testuser [password] => 9e0bc7638cd9329b009d877c88640b6a [email] => test@example.com [profile] => [firstname] => John [lastname] => Sample [title] => Sales Manager [userlevel] => 5 [salt] => bc0f672738c0ed66c0fbcac7ca4bfd61 )
Could someone please explain me why no data gets stored in the salt field?