From dd6e98fe28dfbc41edfb35edbd32139f5f070a50 Mon Sep 17 00:00:00 2001 From: Max538 Date: Mon, 23 Jun 2025 14:14:25 +0200 Subject: [PATCH] implemented update pw function --- Model/AuthModel.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Model/AuthModel.php b/Model/AuthModel.php index 89baa64..e71d4c1 100644 --- a/Model/AuthModel.php +++ b/Model/AuthModel.php @@ -123,7 +123,7 @@ class AuthModel extends Database $randomPw = bin2hex(random_bytes(12 / 2)); $hashedPassword = password_hash($randomPw, PASSWORD_DEFAULT); - + $this->forgottenPwUpdate($email, $hashedPassword); $betreff = "Passwort zurücksetzen bei bibArts"; $nachricht = "Hallo,\n\nhier ihr temporäres Passwort:\n\n $randomPw \n\n Bitte beachten Sie, dass das Passwort nur 2 stunden Gülltig ist. \nViele Grüße,\nbibArts Team"; @@ -177,6 +177,35 @@ class AuthModel extends Database } } + public function updatePassword($email, $oldpw, $newpw){ + if(!$this->login($email, $oldpw)) { + return false; + } + + $requiredFields = [$email, $oldpw, $newpw]; + foreach ($requiredFields as $field) { + if (empty($field)) { + return "Bitte füllen Sie alle Felder aus"; + } + } + $hashedPassword = password_hash($newpw, PASSWORD_DEFAULT); + + $sql = "INSERT INTO user (email, password) + VALUES (:email, :password)"; + + try{ + $pdo = $this->linkDB(); + $stmt = $pdo->prepare($sql); + return $stmt->execute([ + ':email' => $email, + ':password' => $hashedPassword, + ]); + } catch (PDOException $e) { + new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e); + die; + } + } + public function checkDoublePw($password1, $password2){ if($password1 === $password2){ return true;