lostpwd.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. function makeRandomPassword() {
  25. $salt = "abchefghjkmnpqrstuvwxyz0123456789";
  26. srand((double)microtime()*1000000);
  27. $i = 0;
  28. $pass = "";
  29. while ($i <= 7) {
  30. $num = rand() % 33;
  31. $tmp = substr($salt, $num, 1);
  32. $pass = $pass . $tmp;
  33. $i++;
  34. }
  35. return $pass;
  36. }
  37. function exec_ogp_module() {
  38. global $db,$view,$settings;
  39. $view->setCharset(get_lang('lang_charset'));
  40. $errorCount = 0;
  41. if(isset($errors)){
  42. unset($errors);
  43. }
  44. $moduleLink = "index.php?m=lostpwd";
  45. $lang_switch = (isset($_GET['lang']) and $_GET['lang'] != "") ? '&lang='.$_GET['lang'] : "";
  46. echo '<h2>'. get_lang("recover") . '</h2>';
  47. // We either need to show the form or process the email address input
  48. if(!isset( $_GET['user_id'] ) AND !isset( $_GET['ch_pass_uid'] )){
  49. if(isset($_POST['email_address'])){
  50. /* Start of Process User Input */
  51. $email_address = trim($_POST['email_address']);
  52. if ( empty($email_address) )
  53. {
  54. $errorCount++;
  55. $errors[] = get_lang('incomplete');
  56. }
  57. if (!stristr($email_address,"@") OR !stristr($email_address,"."))
  58. {
  59. $errorCount++;
  60. $errors[] = get_lang('errormail');
  61. }
  62. if($errorCount == 0){
  63. // Check to see if email address is in the database
  64. $user_info = $db->getUserByEmail($email_address);
  65. if ( empty($user_info) )
  66. {
  67. $errorCount++;
  68. $errors[] = get_lang('errormail');
  69. }
  70. // Still no errors?
  71. if($errorCount == 0){
  72. $user_id = $user_info['user_id'];
  73. $ch_pass_uid = $user_info['users_passwd'];
  74. $subject = get_lang('confirm_change_subject');
  75. $s = ( isset($_SERVER['HTTPS']) and get_true_boolean($_SERVER['HTTPS']) ) ? "s" : "";
  76. $recover_link = '<a href="http'.$s.'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']."&user_id=".$user_id.'&ch_pass_uid='.$ch_pass_uid.
  77. '" >http'.$s.'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']."&user_id=".$user_id.'&ch_pass_uid='.$ch_pass_uid.'</a>';
  78. $message = get_lang_f('confirm_change_password_message',$recover_link);
  79. if (mymail($email_address, $subject, $message, $settings) == TRUE)
  80. {
  81. echo "<p>".get_lang('confirm_send')."</p>";
  82. }
  83. else
  84. {
  85. echo "<p>".get_lang('mail_failed')."</p>";
  86. }
  87. unset($_POST['email_address']);
  88. }
  89. }
  90. }else{
  91. // Show form
  92. $showForm = 1;
  93. }
  94. // Any errors? If so, show the form
  95. if($errorCount > 0){
  96. $showForm = 1;
  97. }
  98. if(isset($showForm) and $showForm == 1){
  99. echo '<table style="width:200px" align="center" >
  100. <tr>
  101. <td colspan=2 >';
  102. // Print errors if there are any
  103. if(isset($errors) && is_array($errors)){
  104. foreach($errors as $error){
  105. echo '<p style="color: red;">' . $error . '</p>';
  106. }
  107. }
  108. echo '<form method="post" action="?m=lostpwd'.$lang_switch.'">
  109. <label for="email_address">' . get_lang("email") . '</label>
  110. </td>
  111. </tr>
  112. <tr>
  113. <td>
  114. <input type="text" title="' . get_lang("enter_email") . '" name="email_address" size="30" value="';
  115. if(isset($email_address)){
  116. echo $email_address;
  117. }
  118. echo '"/>
  119. </td>
  120. </tr>
  121. <tr>
  122. <td style="text-align:right;">
  123. <input type="submit" value="' . get_lang("submit") . '" class="submit-button"/>
  124. </form>
  125. </td>
  126. </tr>
  127. <tr>
  128. <td style="text-align:left;">
  129. <form method="post" action="index.php' . str_replace("&","?",$lang_switch) . '" style="margin-top:-28px;">
  130. <input type="submit" value="<<&nbsp;' . get_lang("back") .'" class="submit-button"/>
  131. </form>
  132. </td>
  133. </tr></table>';
  134. }
  135. }else if(isset( $_GET['user_id'] ) AND isset( $_GET['ch_pass_uid'] )){
  136. $user_id = trim($_GET['user_id']);
  137. $ch_pass_uid = trim($_GET['ch_pass_uid']);
  138. $user_info = $db->getUserById($user_id);
  139. if ( empty($user_info) )
  140. {
  141. print_failure(get_lang('errormail'));
  142. echo "<p><a href='" . $moduleLink . "'>&lt;&lt; ".get_lang('back')."</a></p>";
  143. return;
  144. }
  145. $email_address = $user_info['users_email'];
  146. $random_password = makeRandomPassword();
  147. $db_password = md5($random_password);
  148. $old_pass_md5_hash = $user_info['users_passwd'];
  149. if ( $old_pass_md5_hash != $ch_pass_uid )
  150. {
  151. print_failure("Failed to update password for user.");
  152. echo "<p><a href='" . $moduleLink . "'>&lt;&lt; ".get_lang('back')."</a></p>";
  153. return;
  154. }
  155. $random_password = makeRandomPassword();
  156. $db_password = md5($random_password);
  157. if ( $db->updateUsersPassword($user_id,$db_password) === FALSE )
  158. {
  159. print_failure("Failed to update password for user.");
  160. echo "<p><a href='" . $moduleLink . "'>&lt;&lt; ".get_lang('back')."</a></p>";
  161. return;
  162. }
  163. $subject = get_lang('subject');
  164. $message = get_lang_f('password_message',$random_password);
  165. if (mymail($email_address, $subject, $message, $settings) == TRUE)
  166. {
  167. echo "<p>".get_lang('send')."</p>";
  168. }
  169. else
  170. {
  171. echo "<p>".get_lang('mail_failed')."</p>";
  172. }
  173. echo "<p>".get_lang('click')." <a href='index.php'>".get_lang('here')."</a> ".get_lang('to_login')."</p>";
  174. }else{
  175. print_failure("Security alert.");
  176. }
  177. }
  178. ?>