$token ]); if(!$user) throw new Exception(_("Invalid reset token.")); $submit = http::value("submit"); if($submit) { try { Core::validateCSRFToken($submit); $form_exception = new FormException; $password = http::value("password"); $password_confirm = http::value("password_confirm"); if($password != $password_confirm) $form_exception->addError(_("Passwords do not match.")); if(!User::validatePassword($password)) $form_exception->addError(_("Password must be at least 6 characters in length and contain at least one lowercase, uppercase, number and special character.")); if($form_exception->hasErrors()) throw $form_exception; $user->password = password_hash($password, PASSWORD_DEFAULT, ["cost" => 14]); $success = $user->commit(); Core::addAlert("success", _("Password reset successfully. You can now log in.")); HTTP::redirect("/log-in"); } catch(FormException $e) { $e->generateAlerts(); } catch(Exception $e) { Core::addAlert("danger", $e->getMessage()); } } } else { $submit = http::value("submit"); if($submit) { try { Core::validateCSRFToken($submit); $form_exception = new FormException; $email = http::value("email", "email"); if(!Form::checkRecaptcha()) $form_exception->addError(_("reCAPTCHA check failed.")); if(empty($email)) $form_exception->addError(_("Invalid email address.")); if($form_exception->hasErrors()) throw $form_exception; $user = User::queryOne(["email" => db::escape($email)]); if($user) { $user->sendPasswordResetEmail(); } else { sleep(2); } Core::addAlert("success", _("A password reset email has been sent to the address provided if an account exists. Follow the instructions in the email to reset your password.")); HTTP::redirect("/log-in"); } catch(FormException $e) { $e->generateAlerts(); } catch(Exception $e) { Core::addAlert("danger", $e->getMessage()); } } } View::includeOnce("header", compact("page_title")); View::include("reset_password", compact("token")); View::includeOnce("footer"); ?>