md5 password

Please help me i am new in Yii framework. actually in my site controller there is no registration function only one user are login in admin panel. So the credential are come form db but user are edit there profile form admin panel and at the time of edit profile the user password is save in md5 form in database and also retrieve that password at the time of login.

Here is my AdminController edit profile function.


	public function actionEditprofile()

				{	

				if(isset($_POST['editform']))    

				{  	

				$password = $_POST['password'];  

				$firstname = $_POST['firstname'];

				$lastname = $_POST['lastname'];  

				$email = $_POST['email'];    	

				

				$attribute['firstname']=$_POST['firstname'];

				$attribute['lastname']=$_POST['lastname'];

				$attribute['email']=$_POST['email'];

				if($_POST['password']==!null){  

				$attribute['password']=$password;

				}   

				

				$condition['condition']="id='".$_POST['postid']."'";

				$editprofile = Login::model()->updateAll($attribute,$condition);

				

				if($editprofile == null)   

			   

			   {

				$editprofile  = new Login;        

				$editprofile->password = $password;

				$editprofile->firstname = $firstname;

				$editprofile->lastname = $lastname;

				$editprofile->email = $email;

				if($editprofile->save())

				{

				$this->render("editprofile",array("msg"=>"You Are Not Input Any Text Field! So Profile 'As Same As' Previous One. Thankyou"));

				}else

				

				{

				$this->render("editprofile",array("msg"=>"You Are Not Input Any Text Fields! So Profile 'As Same As' Previous One. Thankyou"));

				}

				

				}else

				{

				$this->render("editprofile",array("msg"=>"Profile Update Successfully. Thankyou"));	

				}

				}elseif(isset($_POST['editform']))

				{

			    $password = $_POST['password'];  

				$firstname = $_POST['firstname'];

				$lastname = $_POST['lastname'];  

				$email = $_POST['email'];    	

				$attribute['firstname']=$_POST['firstname'];

				$attribute['lastname']=$_POST['lastname'];

				$attribute['email']=$_POST['email'];

				if($_POST['password']['error']==0){

				$attribute['password']=$password;

				}

				$condition['condition']="id='".$_POST['postid']."'";

				$editprofile = Login::model()->updateAll($attribute,$condition);

				if($editprofile == null)

				{   

				$editprofile  = new Login;

				$editprofile->password = $password; 

				$editprofile->firstname = $firstname; 

				$editprofile->lastname = $lastname; 

				$editprofile->email = $email; 

				if($editprofile->save())

				{   	

					$this->render("editprofile",array("msg"=>"Profile Update"));

				}else

				{

					$this->render("editprofile",array("msg"=>"Profile Not Update"));

				}

				}else

				{

					$this->render("editprofile",array("msg"=>"Profile Not Update"));

				}

			}else 

			{

					$this->render('editprofile');

					

			}

			}

Here is my SiteController


public function beforeAction($action) {

				if (Yii::app()->user->isGuest && Yii::app()->controller->action->id != "login") {

					Yii::app()->user->loginRequired();

				}

				//something code right here if user valid

				return true;

						

				}

				

				public function actionIndex()

				{        

				if (Yii::app()->user->isGuest)

				$this->redirect(Yii::app()->createUrl('site/login'));

				else

				$this->render('index');

				}

				

				

				


			 public function actionError()

		{

			if($error=Yii::app()->errorHandler->error)

		{

			if(Yii::app()->request->isAjaxRequest)

				

			    echo $error['Page Not Found! Either Go To Login Page Or Index Page'];

			else

			    $this->render('error', $error);

		}

	}

    

			   public function actionLogin()

			  {  

			   $session=Yii::app()->session;

			   if(strtolower(Yii::app()->user->name)=='guest'){

			   $model=new LoginForm;

			  // if it is ajax validation request

			  if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')

			 {

				echo CActiveForm::validate($model);

				Yii::app()->end();

			 }

			  // collect user input data

				if(isset($_POST['LoginForm']))   

			 {

				$model->attributes=$_POST['LoginForm'];    				

				// validate user input and redirect to the previous page if valid				

				if($model->validate() && $model->login())			

				$this->redirect(array("index"));

			 }    

			    /*if(!isset($_POST['LoginForm'])){  

				Yii::app()->user->logout();

				}*/

		

			    // display the login form 

		   		

				if (Yii::app()->user->isGuest)

				$this->render('login',array('model'=>$model));

			 }

				else{

				$this->redirect(array("index"));

			 }  

		 }   

		 

			// display the login form


			  public function actionLogout()

			{

				Yii::app()->user->logout();

				Yii::app()->user->clearStates();				

				$this->redirect(Yii::app()->homeUrl);	

			}

Here is my Login model


<?php


/**

 * This is the model class for table "tb_login".

 *

 * The followings are the available columns in table 'tb_login':

 * @property integer $id

 * @property string $user

 * @property string $password

 * @property string $email

 * @property string $firstname

 * @property string $lastname

 */

class Login extends CActiveRecord

{

	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'tb_login';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('user, password, email, firstname, lastname', 'required'),

			array('user, password, email, firstname, lastname', 'length', 'max'=>255),

			// The following rule is used by search().

			// @todo Please remove those attributes that should not be searched.

			array('id, user, password, email, firstname, lastname', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

		);

	}




	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => 'ID',

			'user' => 'User',

			'password' => 'Password',

			'email' => 'Email',

			'firstname' => 'Firstname',

			'lastname' => 'Lastname',

		);

	}

	

	public function setPassword($password)

	{

		$this->password_hash = Yii::$app->security->generatePasswordHash($password);

	}

	

	  public function safeAttributes()

      {

          return array(

              parent::safeAttributes(),

              'login' => 'username, password',

          );

      }

        

      public function beforeSave() 

      { 

          $pass = md5(md5($this->password).Yii::app()->params["salt"]);  

          $this->password = $pass; 

          return true; 

      }


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 *

	 * Typical usecase:

	 * - Initialize the model fields with values from filter form.

	 * - Execute this method to get CActiveDataProvider instance which will filter

	 * models according to data in model fields.

	 * - Pass data provider to CGridView, CListView or any similar widget.

	 *

	 * @return CActiveDataProvider the data provider that can return the models

	 * based on the search/filter conditions.

	 */

	public function search()

	{

		// @todo Please modify the following code to remove attributes that should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

		$criteria->compare('user',$this->user,true);

		$criteria->compare('password',$this->password,true);

		$criteria->compare('email',$this->email,true);

		$criteria->compare('firstname',$this->firstname,true);

		$criteria->compare('lastname',$this->lastname,true);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}


	/**

	 * Returns the static model of the specified AR class.

	 * Please note that you should have this exact method in all your CActiveRecord descendants!

	 * @param string $className active record class name.

	 * @return Login the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}

}



Here is my ApplicationBehaviour Component,


<?php

class ApplicationBehavior extends CBehavior

{       private $_owner;

        

        public function events() 

        {


                    return  array(

                               'onBeginRequest'=>'denyEverything',                            

                        );

        }

		

        public function denyEverything()

       {

                   $owner=$this->getOwner();  

                   if($owner->user->getIsGuest())

                        $owner->catchAllRequest=array("site/login");

					    $owner->catchAllRequest=(Yii::app()->createUrl('site/login'));

						

       }

			    

}

?>

Thanks Please help me to find the best solution.

Hi Alokkr,

Very simple use md5 function in your edit action function.




$password = md5($_POST['password']);