PageRenderTime 95ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/recoverpassword.php

http://n-13news.googlecode.com/
PHP | 128 lines | 101 code | 10 blank | 17 comment | 10 complexity | 01a17ab47dd89f1a567f2e5f14c436c3 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?php
  2. /***********************************************************************
  3. N-13 News is a free news publishing system
  4. Copyright (C) 2009 Chris Watt
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program.If not, see <http://www.gnu.org/licenses/>.
  15. ***********************************************************************/
  16. if (!defined('ABSPATH')){ die(); }
  17. echo ' <div id="pageLeft">
  18. <div id="pageIconHome"></div><!--icon-->
  19. <div id="titleHome">N-13 News<br />'. $version . '</div>
  20. </div><!--leftside-->';
  21. echo '<div id="pageRight">';
  22. echo '<div class="headertitle">';
  23. echo '<span class="header">' . $langmsg['recover'][0] . '</span>';
  24. echo '</div>';
  25. $_GET['vcode'] = (empty($_GET['vcode'])) ? '' : $_GET['vcode'];
  26. $_POST['S1'] = (empty($_POST['S1'])) ? '' : $_POST['S1'];
  27. $_POST['email'] = (empty($_POST['email'])) ? '' : $_POST['email'];
  28. if(!$_GET['vcode']){
  29. echo "<div class=subheaders>".$langmsg['recover'][1]."</div>";
  30. if(!$_POST['S1']){
  31. echo "<div class=\"subheaders_body displaytable\">";
  32. echo "<form method=\"post\" action=\"?action=recoverpass\">";
  33. echo $langmsg['recover'][2]." <input type=\"text\" name=\"email\">&nbsp;<input type=\"submit\" name=\"S1\" value=\"".$langmsg['submitfield'][9]."\">";
  34. echo "</form>";
  35. echo "</div>";
  36. }else{
  37. echo "<div class=\"subheaders_body displaytable\">";
  38. $email = $_POST['email'];
  39. $userexists = DataAccess::fetch("SELECT uid, vcode FROM " . NEWS_USERS . " WHERE email = ?", $email);
  40. if(count($userexists) >= 1){
  41. $vcode = $userexists['0']['vcode'];
  42. if(!$vcode){
  43. $vcode = rand(1,10000000);
  44. $vcode = md5($hash . uniqid($vcode));
  45. DataAccess::put("UPDATE " . NEWS_USERS . " SET vcode = ? WHERE email = ?", $vcode, $email);
  46. }
  47. $domain = $_SERVER['HTTP_HOST'];
  48. $headers = "MIME-Version: 1.0\r\n";
  49. $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
  50. $headers .= "From: Account Recovery <noreply@$domain>\r\n";
  51. $headers .= "To: $email <$email>\r\n";
  52. $headers .= "Date: ".date("r")."\r\n";
  53. $headers .= "Subject: Account info\r\n";
  54. $message = $langmsg['recover'][3];
  55. $message .= "<br><br>";
  56. $message .= "<a href=\"http://$_SERVER[HTTP_HOST]$_SERVER[PHP_SELF]?action=recoverpass&vcode=$vcode&email=$email\">".$langmsg['recover'][4]."</a>";
  57. if(@mail($email,"Account info",$message,$headers)){
  58. $g = $langmsg['recover'][5];
  59. $g .= " <b>$email</b> " . $langmsg['recover'][13];
  60. echo $g;
  61. }else{
  62. echo "<span class=\"error\">".$langmsg['recover'][9]."</span>";
  63. }
  64. }else{
  65. echo "<div class=error>".$langmsg['recover'][6]."</div>";
  66. }
  67. echo "</div>";
  68. }
  69. }else{
  70. $userexists = DataAccess::fetch("SELECT user FROM " . NEWS_USERS . " WHERE vcode = ? AND email = ?", $_GET['vcode'], $_GET['email']);
  71. if(count($userexists) >= 1){
  72. $email = $_GET['email'];
  73. $vcode = $_GET['vcode'];
  74. $name = $userexists['0']['user'];
  75. function resetpassform($name){
  76. $email = $_GET['email'];
  77. $vcode = $_GET['vcode'];
  78. $_POST['T1'] = (empty($_POST['T1'])) ? '' : $_POST['T1'];
  79. $_POST['T2'] = (empty($_POST['T2'])) ? '' : $_POST['T2'];
  80. global $langmsg;
  81. echo "<div class=\"subheaders\">".$langmsg['recover'][8]."</div>";
  82. echo "<div class=\"subheaders_body displaytable\">";
  83. echo "<form method=post action=\"?action=recoverpass&vcode=$vcode&email=$email\">";
  84. echo "<table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"81%\">\n";
  85. echo "<tr><td width=\"150\"><div class=ok>$name</div></td></tr>";
  86. echo "<tr><td width=\"150\">".$langmsg['recover'][7].":</td><td><input type=\"password\" name=\"T1\" value=\"$_POST[T1]\"></td></tr>";
  87. echo "<tr><td width=\"150\">".$langmsg['recover'][10]."</td><td><input type=\"password\" name=\"T2\" value=\"$_POST[T2]\"></td></tr>";
  88. echo "<tr><td width=\"150\"></td><td><input type=submit name=S1 value=\"".$langmsg['submitfield'][6]."\"></td></tr>";
  89. echo "</table>";
  90. echo "</form>";
  91. echo "</div>";
  92. }
  93. if(!$_POST['S1']){
  94. resetpassform($name);
  95. }else{
  96. if(!$_POST['T1'] OR !$_POST['T2']){
  97. echo "<div class=error>".$langmsg['recover'][11]."</div>";
  98. resetpassform($name);
  99. }elseif($_POST['T1'] == $_POST['T2']){
  100. $pass = $_POST['T1'];
  101. $pass = md5(SALT . $pass);
  102. DataAccess::put(sprintf("UPDATE %s SET pass = ?, newpass = ?, vcode = ? WHERE email = ? AND vcode = ?", NEWS_USERS), "", $pass, "", $email, $vcode);
  103. echo "<div class=success>".$langmsg['recover'][12]."</div><br><a href=\"?\">Login here!</a>";
  104. }else{
  105. echo "<div class=error>".$langmsg['recover'][11]."</div>";
  106. resetpassform($name);
  107. }
  108. }
  109. }else{
  110. echo "Go away! :o";
  111. }
  112. }
  113. echo " </div><!--rightside-->
  114. </div><!--pageCont-->";
  115. ?>