Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. <?php
  2. function genRandomString($length) {
  3.     $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
  4.     $string = '';    
  5.     for ($p = 0; $p < $length; $p++) {
  6.         $string .= $characters[mt_rand(0, strlen($characters))];
  7.     }
  8.     return $string;
  9. }
  10.  
  11. include('db-connect.php');
  12. $to = $_POST['email'];
  13. $password = genRandomString(8);
  14. $salt = "blahblahblah";
  15. $hash = sha1($salt . $password) . sha1($password . $salt);
  16.  
  17. # This commented out code is just for testing, IRC friends.
  18. # It also throws an exception at $STH->fetch();
  19. #    $STH = $DBH->prepare("UPDATE members SET password=? WHERE email=?");
  20. #    $STH->execute(array($hash, $to));
  21. #    $STH->fetch();
  22.  
  23. try {
  24.     $STH = $DBH->prepare("UPDATE members SET password=? WHERE email=?");
  25.     $STH->execute(array($hash, $to));
  26. } catch(PDOException $e) {
  27.     $exit = "There was a database error. Try again or <a href='contact'>let us know</a>.";
  28.     include('forgot.php');
  29.     exit(1);
  30. }
  31. try {
  32.     if (! $STH->fetch()) {
  33.         $exit = "The e-mail address you submitted was not found in the database.";
  34.         include('forgot.php');
  35.         exit(1);
  36.     }
  37. } catch(PDOException $e) {
  38.     $exit = $e;
  39.     include('forgot.php');
  40.     exit(1);
  41. }
  42. $subject = 'ESL School Rater Login Info';
  43. $message = "Howdy!\r\rAs requested, here is your login information:\r\rusername: $username\rpassword: $password\r\rMosey on over to $_URL/login to login, and don't forget to change your password in your profile!\r\rHasta la vista!\r\rESL School Rater";
  44. $headers = "From:noreply@eslschoolrater.com\r\nReply-To:noreply@eslschoolrater.com\r\nX-Mailer:PHP/" . phpversion();
  45. if (mail($to, $subject, $message, $headers) == false) {
  46.     $exit = 'The email couldn\'t be sent. Are you sure you entered a valid address?';
  47.     include('forgot.php');
  48.     exit(1);
  49. }
  50. $exit = 'Password successfully reset!';
  51. include('forgot.php');
  52. exit(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement