after Validate correct usage

First of all, hi, i’m Marvin, i’m a newbie to Yii, but maybe i’ll become addicted [hi Marv]

I’m searching for the right way to use after validate (which i think is the good method) : i have a form, with login and password, for user creation (not website user, just a part of it, so i created my own database table).

If it’s a creation, i just need the password to be sha1 encoded before being sent to the database, for secure storage.

But i can’t find the correct way to say to yii “if data is correct then crypt the password and after this continue with the db insertion”.

Thanks for your help

beforeSave() is what you are looking for. It won’t be called when validation fails.




protected function beforeSave()

{

  if ($this->isNewRecord) {

	$this->passwordHash = sha1($this->password);

  }

  return parent::beforeSave(); // don't forget this line!

}



Seems to be just what i needed, thanks