/phpmyfaq/admin/password.php

https://github.com/max-koehler/phpMyFAQ · PHP · 145 lines · 83 code · 23 blank · 39 comment · 16 complexity · b9637503ddddbdc7efa31d496b747586 MD5 · raw file

  1. <?php
  2. /**
  3. * Reset a forgotten password to a new one.
  4. *
  5. * @package phpMyFAQ
  6. * @subpackage Administration
  7. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  8. * @since 2004-05-11
  9. * @version SVN: $Id$
  10. * @copyright 2004-2009 phpMyFAQ Team
  11. *
  12. * The contents of this file are subject to the Mozilla Public License
  13. * Version 1.1 (the "License"); you may not use this file except in
  14. * compliance with the License. You may obtain a copy of the License at
  15. * http://www.mozilla.org/MPL/
  16. *
  17. * Software distributed under the License is distributed on an "AS IS"
  18. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  19. * License for the specific language governing rights and limitations
  20. * under the License.
  21. */
  22. define('PMF_ROOT_DIR', dirname(dirname(__FILE__)));
  23. //
  24. // Check if config/database.php exist -> if not, redirect to installer
  25. //
  26. if (!file_exists(PMF_ROOT_DIR . '/config/database.php')) {
  27. header("Location: ".str_replace('admin/index.php', '', $_SERVER["PHP_SELF"])."install/setup.php");
  28. exit();
  29. }
  30. //
  31. // Define the named constant used as a check by any included PHP file
  32. //
  33. define('IS_VALID_PHPMYFAQ_ADMIN', null);
  34. //
  35. // Autoload classes, prepend and start the PHP session
  36. //
  37. require_once PMF_ROOT_DIR.'/inc/Init.php';
  38. PMF_Init::cleanRequest();
  39. session_name(PMF_COOKIE_NAME_AUTH.trim($faqconfig->get('main.phpMyFAQToken')));
  40. session_start();
  41. //
  42. // get language (default: english)
  43. //
  44. $Language = new PMF_Language();
  45. $LANGCODE = $Language->setLanguage($faqconfig->get('main.languageDetection'), $faqconfig->get('main.language'));
  46. // Preload English strings
  47. require_once PMF_ROOT_DIR.'/lang/language_en.php';
  48. if (isset($LANGCODE) && PMF_Language::isASupportedLanguage($LANGCODE)) {
  49. // Overwrite English strings with the ones we have in the current language
  50. require_once PMF_ROOT_DIR.'/lang/language_'.$LANGCODE.'.php';
  51. } else {
  52. $LANGCODE = 'en';
  53. }
  54. //
  55. // Initalizing static string wrapper
  56. //
  57. PMF_String::init($LANGCODE);
  58. /* header of the admin page */
  59. require_once ("header.php");
  60. ?>
  61. </div>
  62. <div id="bodyText">
  63. <?php
  64. $action = PMF_Filter::filterInput(INPUT_GET, 'action', FILTER_SANITIZE_STRING);
  65. if ($action == "sendmail") {
  66. $username = PMF_Filter::filterInput(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
  67. $email = PMF_Filter::filterInput(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
  68. if (!is_null($username) && !is_null($email)) {
  69. $user = new PMF_User_CurrentUser();
  70. $loginExist = $user->getUserByLogin($username);
  71. if ($loginExist && ($email == $user->getUserData('email'))) {
  72. $consonants = array(
  73. 'b','c','d','f','g','h','j','k','l','m','n','p','r','s','t','v','w','x','y','z'
  74. );
  75. $vowels = array(
  76. 'a','e','i','o','u'
  77. );
  78. $newPassword = '';
  79. srand((double)microtime()*1000000);
  80. for ($i = 1; $i <= 4; $i++) {
  81. $newPassword .= $consonants[rand(0,19)];
  82. $newPassword .= $vowels[rand(0,4)];
  83. }
  84. $user->changePassword($newPassword);
  85. $text = $PMF_LANG['lostpwd_text_1']."\nUsername: ".$username."\nNew Password: ".$newPassword."\n\n".$PMF_LANG["lostpwd_text_2"];
  86. $mail = new PMF_Mail();
  87. $mail->addTo($email);
  88. $mail->subject = '[%sitename%] Username / password request';
  89. $mail->message = $text;
  90. $result = $mail->send();
  91. unset($mail);
  92. // Trust that the email has been sent
  93. print $PMF_LANG["lostpwd_mail_okay"];
  94. print "<p><img src=\"images/arrow.gif\" width=\"11\" height=\"11\" alt=\"".$PMF_LANG["ad"]."\" border=\"0\" /> <a href=\"index.php\" title=\"".$PMF_LANG["ad"]."\">".$PMF_LANG["ad"]."</a></p>";
  95. } else {
  96. print $PMF_LANG["lostpwd_err_1"];
  97. }
  98. } else {
  99. print $PMF_LANG["lostpwd_err_2"];
  100. }
  101. } else {
  102. ?>
  103. <form action="?action=sendmail" method="post">
  104. <fieldset class="login">
  105. <legend class="login"><?php print $PMF_LANG["ad_passwd_cop"]; ?></legend>
  106. <label class="left"><?php print $PMF_LANG["ad_auth_user"]; ?></label>
  107. <input type="text" name="username" size="30" /><br />
  108. <label class="left"><?php print $PMF_LANG["ad_entry_email"]; ?></label>
  109. <input type="text" name="email" size="30" /><br />
  110. <input class="submit" type="submit" value="<?php print $PMF_LANG["msgNewContentSubmit"]; ?>" />
  111. <p><img src="images/arrow.gif" width="11" height="11" alt="<?php print $PMF_LANG["ad_sess_back"]; ?> FAQ" border="0" /> <a href="index.php" title="<?php print $PMF_LANG["ad_sess_back"]; ?> FAQ"><?php print $PMF_LANG["ad_sess_back"]; ?></a></p>
  112. <p><img src="images/arrow.gif" width="11" height="11" alt="<?php print $faqconfig->get('main.titleFAQ'); ?> FAQ" border="0" /> <a href="../index.php" title="<?php print $faqconfig->get('main.titleFAQ'); ?> FAQ"><?php print $faqconfig->get('main.titleFAQ'); ?> FAQ</a></p>
  113. </fieldset>
  114. </form>
  115. <?php
  116. }
  117. if (DEBUG) {
  118. print "\n<p>DEBUG INFORMATION:</p>\n";
  119. print "<p>".$db->sqllog()."</p>";
  120. }
  121. require_once 'footer.php';
  122. $db->dbclose();