本文整理匯總了PHP中UserDB::updatePassword方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserDB::updatePassword方法的具體用法?PHP UserDB::updatePassword怎麽用?PHP UserDB::updatePassword使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserDB
的用法示例。
在下文中一共展示了UserDB::updatePassword方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: post
public static function post()
{
if (isset($_POST['save'])) {
$page = new Page();
$page->data['title'] = 'Wachtwoord wijzigen';
$errMsgs = ChangePasswordViewValidator::validate($_POST);
if (empty($errMsgs)) {
try {
$passwordSalt = UserDB::getPasswordSaltByUserId($_SESSION['Stippers']['user']->userId);
$oldPasswordHash = hash_pbkdf2('sha256', $_POST['old_password'], $passwordSalt, SecurityConfig::N_PASSWORD_HASH_ITERATIONS);
//If the old password is incorrect, show an error
if ($_SESSION['Stippers']['ChangePassword']['user']->passwordHash != $oldPasswordHash) {
ChangePasswordController::buildChangePasswordView($page);
$page->data['ChangePasswordView']['errMsgs']['global'] = '<h2 class="error_message" id="change_password_form_error_message">Het oude wachtwoord is fout.</h2>';
} else {
$newPasswordHash = hash_pbkdf2('sha256', $_POST['new_password'], $passwordSalt, SecurityConfig::N_PASSWORD_HASH_ITERATIONS);
UserDB::updatePassword($_SESSION['Stippers']['ChangePassword']['user'], $newPasswordHash);
$_SESSION['Stippers']['user']->passwordHash = $newPasswordHash;
//Show success view
$page->data['SuccessMessageNoDescriptionWithLinkView']['successTitle'] = 'Wachtwoord succesvol gewijzigd';
$page->data['SuccessMessageNoDescriptionWithLinkView']['redirectUrl'] = 'profile';
$page->addView('success/SuccessMessageNoDescriptionWithLinkView');
}
} catch (UserDBException $ex) {
//Show correct error message for errors
if ($ex->getCode() == UserDBException::USEROUTOFDATE) {
$page->data['ErrorMessageWithDescriptionWithLinkView']['errorTitle'] = 'Wachtwoord niet gewijzigd';
$page->data['ErrorMessageWithDescriptionWithLinkView']['errorDescription'] = 'Iemand anders heeft je gegevens in tussentijd al gewijzigd.';
$page->data['ErrorMessageWithDescriptionWithLinkView']['tryAgainUrl'] = $_SERVER['REQUEST_URI'];
$page->addView('error/ErrorMessageWithDescriptionWithLinkView');
} else {
ChangePasswordController::buildChangePasswordView($page);
$page->data['ChangePasswordView']['errMsgs']['global'] = '<h2 class="error_message" id="change_password_form_error_message">Kan wachtwoord niet wijzigen, probeer het opnieuw.</h2>';
}
} catch (Exception $ex) {
ChangePasswordController::buildChangePasswordView($page);
$page->data['ChangePasswordView']['errMsgs']['global'] = '<h2 class="error_message" id="change_password_form_error_message">Kan wachtwoord niet wijzigen, probeer het opnieuw.</h2>';
}
} else {
//If we had an error we show the page again with errors
ChangePasswordController::buildChangePasswordView($page);
$page->data['ChangePasswordView']['errMsgs'] = array_merge($page->data['ChangePasswordView']['errMsgs'], $errMsgs);
}
$page->showWithMenu();
} else {
ChangePasswordController::get();
}
}