protected function beforeSave() { if (parent::beforeSave()) { if ($this->isNewRecord) { if (UserIdentity::isCrypted($this->password)) { $this->password = UserIdentity::crypt($this->password); } } return true; } return false; }