Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Password Encryption

$
0
0
I have created a user controller. on create record its wrking fine but while updating record i dont want to enter password every time means password should be update when i change it other wise not. code is given below

<?php 
		if(isset($_POST['User']))
		{
			//$model->attributes=$_POST['User'];
			
			if(!empty($_POST['User']['password']))
			{
				$model->password=$_POST['User']['password'];
			}
			$model->username=$_POST['User']['username'];
			$model->firstname=$_POST['User']['firstname'];
			$model->lastname=$_POST['User']['lastname'];
			$model->email=$_POST['User']['email'];
			$model->status=$_POST['User']['status'];
			$model->role=$_POST['User']['role'];
				if($model->save())
			{
				Yii::app()->user->setFlash('success', "Record Has Been Updated");
				$this->redirect(array('admin'));
			}
		} ?>



Now the issue is i want to encrypt password before save. i also use beforesave() in model to encrypt password but it always encrypt password either password field is empty or not.

	  public function beforeSave() 
    {
	
      if (!empty($this->password))
        { $this->password=md5($this->password);}

    
	 //  return parent::beforeSave();
    }


Can anyone guide what is wrong i am doing here and which encryption we should use MD5 or crypt ?

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>