Frontend\Modules\Profiles\Engine\Authentication::updatePassword PHP Метод

updatePassword() публичный статический Метод

Update profile password and salt.
public static updatePassword ( integer $profileId, string $password )
$profileId integer Profile id for which we are changing the password.
$password string New password.
    public static function updatePassword($profileId, $password)
    {
        $profileId = (int) $profileId;
        $password = (string) $password;
        // get new salt
        $salt = FrontendProfilesModel::getRandomString();
        // encrypt password
        $encryptedPassword = FrontendProfilesModel::getEncryptedString($password, $salt);
        // update salt
        FrontendProfilesModel::setSetting($profileId, 'salt', $salt);
        // update password
        FrontendProfilesModel::update($profileId, array('password' => $encryptedPassword));
    }

Usage Example

Пример #1
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtPassword = $this->frm->getField('password');
         // field is filled in?
         $txtPassword->isFilled(FL::getError('PasswordIsRequired'));
         // valid
         if ($this->frm->isCorrect()) {
             // get profile id
             $profileId = FrontendProfilesModel::getIdBySetting('forgot_password_key', $this->URL->getParameter(0));
             // remove key (we can only update the password once with this key)
             FrontendProfilesModel::deleteSetting($profileId, 'forgot_password_key');
             // update password
             FrontendProfilesAuthentication::updatePassword($profileId, $txtPassword->getValue());
             // login (check again because we might have logged in in the meanwhile)
             if (!FrontendProfilesAuthentication::isLoggedIn()) {
                 FrontendProfilesAuthentication::login($profileId);
             }
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_reset_password', array('id' => $profileId));
             // redirect
             $this->redirect(FrontendNavigation::getURLForBlock('Profiles', 'ResetPassword') . '/' . $this->URL->getParameter(0) . '?sent=true');
         } else {
             $this->tpl->assign('forgotPasswordHasError', true);
         }
     }
 }
All Usage Examples Of Frontend\Modules\Profiles\Engine\Authentication::updatePassword