assign("username", $_REQUEST["username"]); if (isset($_REQUEST["submit"])) { try { if (!$_REQUEST["username"] || !$_REQUEST["oldpassword"] || !$_REQUEST["newpassword"] || !$_REQUEST["newpassword_again"]) throw new Exception(_('You MUST fill in all the fields.')); $username = $db->EscapeString(trim($_REQUEST['username'])); $current_password = $db->EscapeString(trim($_REQUEST['oldpassword'])); $new_password = $db->EscapeString(trim($_REQUEST['newpassword'])); if ($_REQUEST["newpassword"] != $_REQUEST["newpassword_again"]) throw new Exception(_("Passwords do not match.")); // Warning for now, password change only works for local users, registered through our signup process. $user = User::getUserByUsernameAndOrigin($username, LOCAL_USER_ACCOUNT_ORIGIN); if ($user->getPasswordHash() != User::passwordHash($current_password)) throw new Exception(_("Wrong password.")); $user->SetPassword($new_password); $smarty->assign("message", _("Your password has been changed succesfully.")); $smarty->display("templates/validate.html"); exit; } catch (Exception $e) { $smarty->assign("error", $e->getMessage()); } } $smarty->display("templates/change_password.html"); ?>