diff --git a/website/public/resetpassword.php b/website/public/resetpassword.php new file mode 100644 index 0000000..c2f9221 --- /dev/null +++ b/website/public/resetpassword.php @@ -0,0 +1,49 @@ +prepare(" + UPDATE + `user` + SET + `password` = :password + WHERE + `userID` = :userID + "); + $stmt->bindParam(":password", $_POST["password"]); + $stmt->bindParam(":userID", $_POST["u"]); + $stmt->execute(); +} + +function verifyLink(int $userID, string $hash) { + $stmt = $GLOBALS["db"]->prepare(" + SELECT + `password` + FROM + `user` + WHERE + `userID` = :userID + "); + $stmt->bindParam(":userID", $userID); + $password = $stmt->fetch()["password"]; + return password_verify($password, $hash); +} \ No newline at end of file diff --git a/website/public/styles/resetpassword.css b/website/public/styles/resetpassword.css new file mode 100644 index 0000000..a3d7942 --- /dev/null +++ b/website/public/styles/resetpassword.css @@ -0,0 +1,17 @@ +.password-change { + height: 100%; + background-color: #FBC02D; + margin: auto; +} + +.top-logo { + text-align: center; +} + +.item-box { + margin: 30px auto auto; + display: block; +} +.password-change img { + width: 50%; +} diff --git a/website/queries/requestpassword.php b/website/queries/requestpassword.php new file mode 100644 index 0000000..4044058 --- /dev/null +++ b/website/queries/requestpassword.php @@ -0,0 +1,55 @@ +prepare(" + SELECT + `userID`, + `username` + FROM + `user` + WHERE + `email` = :email + "); + $stmt->bindParm("email", $email); + $stmt->execute(); + if (!$stmt->rowCount()) { + // TODO: Just stop. + return; + } + $result = $stmt->fetch(); + $userID = $result["userID"]; + $username = $result["username"]; + $hash = md5(random_int(0, 1000000)); + $hashedHash = password_hash($hash, PASSWORD_DEFAULT); + setHashToDatabase($userID, $hash); + doSendPasswordRecovery($userID, $email, $username, $hashedHash); + + + } else { + // TODO: Be angry! + } +} + +function doSendPasswordRecovery(int $userID, string $email, string $username, string $hash) { + $resetLink = "https://myhyvesbookplus.nl/resetpassword.php?u=$userID&h=$hash"; + + $subject = "Reset uw wachtwoord"; + $body = "Hallo $username,\r\n\r\nKlik op de onderstaande link om uw wachtwoord te resetten.\r\n\r\n$resetLink\r\n\r\nGroeten MyHyvesbook+"; + $header = "From: MyHyvesbook+ "; + mail($email, $subject, $body, $header); +} + +function setHashToDatabase(int $userID, string $hash) { + $stmt = $GLOBALS["db"]->prepare(" + UPDATE + `user` + SET + `password` = $hash + WHERE + `userID` = $userID + "); + $stmt->execute(); + return $stmt->rowCount(); +} \ No newline at end of file diff --git a/website/views/resetpassword.php b/website/views/resetpassword.php new file mode 100644 index 0000000..24d3aaf --- /dev/null +++ b/website/views/resetpassword.php @@ -0,0 +1,47 @@ + + + + + + +
+ + +
+
Voer een nieuw wachtwoord in
+ " + > + " + > +
    +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
+
+
+ + \ No newline at end of file