Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/projects/slutprojekt/

class/
create-categories.php
create-recipe.php
css/
db_content.php
forgot_password.php
include/
login.php
logout.php
recipe-search.php
recipe.php
reset_password.php
signin.php
start.php
tabeller/
verify.php

forgot_password.php

37 lines UTF-8 Windows (CRLF)
<?php
include('../../dbconnection.php');
ob_clean();

if (
$_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['email'])) {
  
$email trim($_POST['email']);
  
$reset_code bin2hex(random_bytes(16));
  
$reset_expires date("Y-m-d H:i:s"time() + 900);

  
$stmt $dbconn->prepare("UPDATE users SET reset_code = :code, reset_expires = :expires WHERE email = :email");
  
$stmt->bindParam(':code'$reset_code);
  
$stmt->bindParam(':expires'$reset_expires);
  
$stmt->bindParam(':email'$email);
  
$stmt->execute();


  
$subject "Återställ ditt lösenord";
  
$message "
    <html><body>
    <h2>Återställ lösenord</h2>
    <p>Klicka här för att återställa lösenordet:</p>
    <a href='https://labb.vgy.se/~davidng/webbsrvprg/projects/slutprojekt/reset_password.php?code=
$reset_code'>Byt lösenord</a>
    </body></html>"
;

  
$headers "MIME-Version: 1.0\r\nContent-Type: text/html; charset=UTF-8\r\nFrom: no-reply@varmdogymnasium.se\r\n";
  
mail($email$subject$message$headers);

  echo 
"Om e-postadressen finns registrerad har ett återställningsmejl skickats.";
}
?>
<h1>Glömt lösenord?</h1>
<form method="post">
  <label for="email">Ange din e-post:</label>
  <input type="email" name="email" required>
  <input type="submit" value="Skicka återställningslänk">
</form>