PageRenderTime 44ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/recover.php

http://thinktankforums.googlecode.com/
PHP | 113 lines | 87 code | 18 blank | 8 comment | 9 complexity | c4305ef46cfeea7334d07fac1f4fe46c MD5 | raw file
Possible License(s): 0BSD
  1. <?php
  2. /* think tank forums
  3. *
  4. * recover.php
  5. */
  6. $ttf_title = $ttf_label = "recover your account";
  7. require_once "include_common.php";
  8. require_once "include_header.php";
  9. // users don't need to recover an account
  10. kill_users();
  11. $id_username = clean($_POST["id_username"]);
  12. $id_email = clean($_POST["id_email"]);
  13. // if we have chosen an account to generate a passkey for
  14. if (!empty($id_username) || !empty($id_email)) {
  15. // first we better see if we can find the user record
  16. $sql = "SELECT user_id, ".
  17. " username, ".
  18. " email ".
  19. "FROM ttf_user ";
  20. if (!empty($id_username)) {
  21. $sql .= " WHERE username='$id_username' ";
  22. } else if (!empty($id_email)) {
  23. $sql .= " WHERE email='$id_email' ";
  24. };
  25. if (!$result = mysql_query($sql)) showerror();
  26. if (mysql_num_rows($result) !== 1) {
  27. message($ttf_label, $ttf_msg["fatal_error"], $ttf_msg["nomatchuser"]);
  28. die();
  29. };
  30. list($user_id, $username, $email) = mysql_fetch_array($result);
  31. // now that we have a matching user, do things!
  32. $password = generate_string(16);
  33. $passkey = generate_string(32);
  34. $sql = "INSERT INTO ttf_recover ".
  35. "SET date=UNIX_TIMESTAMP(), ".
  36. " ip='{$_SERVER["REMOTE_ADDR"]}', ".
  37. " user_id='$user_id', ".
  38. " password=SHA1('$password'), ".
  39. " passkey='$passkey' ";
  40. if (!$result = mysql_query($sql)) showerror();
  41. $subject = "{$ttf_cfg["forum_name"]} account recovery information";
  42. $message =<<<EOF
  43. hello,
  44. here is your account recovery information for {$ttf_cfg["forum_name"]}:
  45. username: {$username}
  46. password: {$password}
  47. passkey: {$passkey}
  48. to begin using this new password, you'll need to activate it using the passkey.
  49. visit {$ttf_protocol}://{$ttf_cfg["address"]}/activate.php
  50. thanks,
  51. {$ttf_cfg["bot_name"]}
  52. p.s. do not reply to this email address; it is not checked.
  53. EOF;
  54. if (!mail($email, $subject, $message, "from: ".$ttf_cfg["bot_email"])) {
  55. // uh oh, the mail() function failed
  56. message($ttf_label, $ttf_msg["fatal_error"], $ttf_msg["cantmail"]);
  57. die();
  58. } else {
  59. // it worked!
  60. message($ttf_label, $ttf_msg["successtitl"], $ttf_msg["mailedinfo"]);
  61. die();
  62. };
  63. };
  64. echo <<<EOF
  65. <div class="contenttitle">recover your account</div>
  66. <div class="contentbox">
  67. <form action="recover.php" method="post">
  68. <div>
  69. which account are you claiming as yours?
  70. identify it in one way below.<br /><br />
  71. username:<br />
  72. <input type="text" name="id_username" /><br /><br />
  73. email:<br />
  74. <input type="text" name="id_email" /><br /><br />
  75. we will send a new password to your email address,
  76. along with a passkey to activate it.<br /><br />
  77. <input type="submit" value="submit" />
  78. </div>
  79. </form>
  80. </div>
  81. EOF;
  82. require_once "include_footer.php";