diff --git a/forgotpass.php b/forgotpass.php index efddf7a..a3e6a8b 100644 --- a/forgotpass.php +++ b/forgotpass.php @@ -40,7 +40,7 @@ if(isset($_GET['send']) ) { $mailrcpt = $user['email']; $mailsubject = "New password for your User"; $from = "From: Password Reset Service "; //place a real address if we use this in production - $url_passwordcode = 'https://loginpagefoo.td00.de/forgotpass.php?userid='.$user['id'].'&code='.$passwordcode; //this shouldnt be my domain in prod.. + $url_passwordcode = 'https://loginpagefoo.td00.de/resetpass.php?userid='.$user['id'].'&code='.$passwordcode; //this shouldnt be my domain in prod.. $text = 'Hallo '.$user['username'].', please use the following URL to change your password in the next 24h: '.$url_passwordcode.' diff --git a/resetpass.php b/resetpass.php new file mode 100644 index 0000000..16000d6 --- /dev/null +++ b/resetpass.php @@ -0,0 +1,60 @@ +prepare("SELECT * FROM users WHERE id = :userid"); +$result = $statement->execute(array('userid' => $userid)); +$user = $statement->fetch(); + +//check if theres a code for the user delivered +if($user === null || $user['passwordcode'] === null) { + die("No User matching your request."); +} + +if($user['passwordcode_time'] === null || strtotime($user['passwordcode_time']) < (time()-24*3600) ) { + die("Ooops. This code isn't valid anymore."); +} + + + +if(sha1($code) != $user['passwordcode']) { + die("Thats not your code. Naughty user!"); +} + + + +if(isset($_GET['send'])) { + $password = $_POST['password']; + $password_confirm = $_POST['password_confirm']; + + if($password != $password_confirm) { + echo "password or confirmed password wrong"; + } else { + $passwordhash = password_hash($password, PASSWORD_DEFAULT); + $statement = $pdo->prepare("UPDATE users SET password = :passwordhash, passwordcode = NULL, passwordcode_time = NULL WHERE id = :userid"); + $result = $statement->execute(array('passwordhash' => $passwordhash, 'userid'=> $userid )); + + if($result) { + die('Changed password. Please goto login now.'); + } + } +} +?> + +

Set new password

+
+Please enter new password:
+

+ +Confirm new password:
+

+ + +
\ No newline at end of file