Yii::t('common/site', 'Username'), 'password' =>Yii::t('common/site', 'Password'), ]; } /** * Validates the password. * This method serves as the inline validation for password. * * @param string $attribute the attribute currently being validated * @param array $params the additional name-value pairs given in the rule * @throws \yii\base\InvalidConfigException */ public function validatePassword($attribute, $params) { if (!$this->hasErrors()) { /** @var \common\models\Customer $user */ $customer = $this->getCustomer(); if (!$customer || !$customer->validatePassword($this->password)) { $this->addError($attribute, 'Incorrect username or password.'); } } } /** * Finds user by [[username]] * * @return Customer|null */ public function getCustomer() { if ( $this->customer === null ){ $this->customer = Customer::findIdentity( $this->username ); } return $this->customer; } }