reset-password.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. $params = array();
  3. parse_str($_POST['reset_password'], $params);
  4. if(!array_key_exists('email-reset-password', $params)) {
  5. echo 400; // Missing parameters
  6. }
  7. else {
  8. // Retrieve user credentials
  9. $email = $params['email-reset-password'];
  10. // echo $email;
  11. require_once('db_utils.php');
  12. $conn = db_connect(); // Connect to the database
  13. // Check if the username already exists
  14. if(!($result = mysqli_query($conn, "SELECT salt, name FROM user WHERE username = '$email'"))) {
  15. echo 400; // Wrong query
  16. }
  17. else if(mysqli_num_rows($result) != 1) { // User not registered or duplicated
  18. echo 401;
  19. }
  20. else { // User registered
  21. //
  22. echo 200;
  23. // Get user details
  24. $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  25. $salt = $row['salt'];
  26. $name = $row['name'];
  27. // Reset password email
  28. $resetLink = "https://ethicscanvas.org/reset.php?salt=$salt";
  29. $resetEmail = "Hi $name,<br><br>We have received a request to reset your password at EthicsCanvas.org.<br><br>Please, click on the link below in order to complete the process:<br>$resetLink<br><br>Thanks,<br><br>Ethics Canvas Team";
  30. // Send activation email
  31. include('mailer.php');
  32. smtpmailer($email, 'Password reset at ethicscanvas.org', $resetEmail, null);
  33. }
  34. }
  35. ?>