onBeforeSave problem

I have a user register (not from Yii crud) page and I want the pass to be md5(pass) so I write this code that does not work, what is wrong?


public function onBeforeSave($event) {

        $pass = md5($this->usr_pass);

        $this->usr_pass= $pass;


        //   $this->usr_pass=md5( $this->usr_pass);

        //  $this->password_repeat=md5( $this->password_repeat);

        //  die( $this->usr_pass);

        return true;


    }

The method should be called "beforeSafe".

Try something like this (in the Model):

public function init(){

    $this->onBeforeSave=array($this,'crypt');


parent::init();

}

public function crypt($event) {

    $model = $event->sender;


    $pass = md5($model->usr_pass);


    $model->usr_pass= $pass;


    $event->isValid=true


    return true;

}

public function beforeSave() {

    $pass = md5($this->usr_pass);


    $this->usr_pass= $pass;





    //   $this->usr_pass=md5( $this->usr_pass);


    //  $this->password_repeat=md5( $this->password_repeat);


    //  die( $this->usr_pass);


    return true;





}

works with me