/** * @inheritdoc */ public function beforeSave($insert) { if ($this->isNewRecord) { $this->password = Yii::$app->getSecurity()->generatePasswordHash($this->password); $this->repeatPassword = $this->password; $this->auth_key = Yii::$app->getSecurity()->generateRandomString(70); } else { if (empty($this->password)) { $this->password = $this->currentPassword; $this->repeatPassword = $this->currentPassword; } else { $this->password = Yii::$app->getSecurity()->generatePasswordHash($this->password); $this->repeatPassword = $this->password; } } return parent::beforeSave($insert); }