Added password change

This commit is contained in:
Marijn Jansen
2017-01-18 10:43:54 +01:00
parent 176851b486
commit dde463df6c
4 changed files with 66 additions and 21 deletions

View File

@@ -21,6 +21,20 @@ function getSettings() {
return $stmt->fetch();
}
function getPasswordHash() {
$stmt = $GLOBALS["db"]->prepare("
SELECT
`password`
FROM
`user`
WHERE
`userID` = :userID
");
$stmt->bindParam(":userID", $_SESSION["userID"]);
$stmt->execute();
return $stmt->fetch();
}
function updateSettings() {
$stmt = $GLOBALS["db"]->prepare("
UPDATE
@@ -42,5 +56,31 @@ function updateSettings() {
$stmt->bindParam(":bio", $_POST["bio"]);
$stmt->bindParam(":userID", $_SESSION["userID"]);
$stmt->execute();
}
function updatePassword() {
if (password_verify($_POST["password-old"], getPasswordHash()["password"])) {
if ($_POST["password-new"] == $_POST["password-confirm"]) {
changePassword();
}
} else {
print("Did not match");
}
}
function changePassword() {
$stmt =$GLOBALS["db"]->prepare("
UPDATE
`user`
SET
`password` = :new_password
WHERE
`userID` = :userID
");
$hashed_password = password_hash($_POST["password-new"], PASSWORD_DEFAULT);
$stmt->bindParam(":new_password", $hashed_password);
$stmt->bindParam(":userID", $_SESSION["userID"]);
$stmt->execute();
}