/** * Adds password validation rule for login scenario * * @param \DevGroup\Users\models\LoginForm $loginForm * * @return array */ protected function validatePassword(LoginForm &$loginForm) { return ['password', function ($attribute) use(&$loginForm) { if ($loginForm->user === null || !PasswordHelper::validate($loginForm->password, $loginForm->user->password_hash)) { $loginForm->addError($attribute, Yii::t('users', 'Invalid login or password')); } }]; }
public function socialRegistrationScenario(RegistrationForm &$registrationForm, BaseClient &$client) { if (empty($registrationForm->username)) { $registrationForm->generateUsername($client->getUserAttributes()); $registrationForm->username_is_temporary = true; } if (empty($registrationForm->password)) { $registrationForm->password = PasswordHelper::generate(UsersModule::module()->generatedPasswordLength); } }
public function changePassword() { /** @var User $user */ $this->trigger(self::EVENT_BEFORE_PASSWORD_CHANGE); $user = Yii::$app->user->identity; if ($user === null) { throw new ServerErrorHttpException("No user identity found"); } if (PasswordHelper::validate($this->oldPassword, $user->password_hash) !== true) { $this->addError('oldPassword', Yii::t('users', 'Old Password not valid')); return false; } else { $this->trigger(self::EVENT_PASSWORD_CHANGE); $user->password = $this->newPassword; return $user->changePassword(); } return false; }
/** * @param string $newPassword * @return bool */ public function changePassword() { if ($this->getIsNewRecord() == true) { throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user'); } $this->trigger(User::EVENT_PASSWORD_CHANGE); $this->password_hash = PasswordHelper::hash($this->password); return $this->save(); }