PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/passwd.php

https://github.com/adamfranco/segue-1.x
PHP | 438 lines | 388 code | 13 blank | 37 comment | 13 complexity | 5bf1cee384a2184d78896ad0a40b6610 MD5 | raw file
  1. <? /* $Id$ */
  2. require("objects/objects.inc.php");
  3. ob_start();
  4. session_start();
  5. // include all necessary files
  6. include("includes.inc.php");
  7. //printpre ($_REQUEST);
  8. /******************************************************************************
  9. * actions:
  10. * login -> auth
  11. * register -> newuser,
  12. * reset -> send,
  13. * change -> newpassword
  14. ******************************************************************************/
  15. if ($_REQUEST[reset] == "reset") $reset = $_REQUEST[reset];
  16. //if ($_REQUEST[email]) $email = $_REQUEST[email];
  17. //if ($_REQUEST[uname]) $uname = $_REQUEST[uname];
  18. /******************************************************************************
  19. * newpassword - changes password
  20. ******************************************************************************/
  21. if ($_REQUEST[action] == "newpassword") {
  22. $authtype = db_get_value("user","user_authtype","user_uname = '".addslashes($_SESSION[auser])."'");
  23. $db_pass = db_get_value("user","user_pass","user_uname = '".addslashes($_SESSION[auser])."'");
  24. if ($authtype != "db") {
  25. $message = "<div align='center'>This password cannot be reset here.</div>";
  26. } else {
  27. $origPassValid = !strcmp($_REQUEST[oldpass],$db_pass);
  28. if ($origPassValid) {
  29. $oldpass = $_REQUEST[oldpass];
  30. $passwordsMatch = !strcmp($_REQUEST[newpass1],$_REQUEST[newpass2]);
  31. if ($passwordsMatch) {
  32. $validLength = ereg(".{8,200}",$_REQUEST[newpass1]);
  33. if ($validLength) {
  34. $validChars = !ereg("[\'\"]",$_REQUEST[newpass1]);
  35. if ($validChars) {
  36. $passwordGood = 1;
  37. $query = "UPDATE user SET user_pass='".addslashes($_REQUEST[newpass1])."' where user_uname='".addslashes($_SESSION[auser])."'";
  38. db_query($query);
  39. } else {
  40. unset($newpass1);
  41. unset($newpass2);
  42. $message = "<div align='center'>New password contains prohibited characters</div>";
  43. }
  44. } else {
  45. unset($newpass1);
  46. unset($newpass2);
  47. $message = "<div align='center'>New password is not between 8 and 200 characters</div>";
  48. }
  49. } else {
  50. unset($newpass1);
  51. unset($newpass2);
  52. $message = "<div align='center'>New passwords don't match</div>";
  53. }
  54. } else {
  55. unset($oldpass);
  56. $message = "<div align='center'>Your old password is invalid</div>";
  57. } // end origPassValid
  58. }// end authtype
  59. if ($passwordGood) {
  60. $message = "<div align='center'>Your password has been changed<br /><br /></div>";
  61. $message .= "<div align='center'><input type='button' value='Return' onclick='window.close()' /></div>";
  62. }
  63. /******************************************************************************
  64. * send || newuser - generates a password and sends to existing or new user
  65. ******************************************************************************/
  66. } else if ($_REQUEST[action] == "send" || $_REQUEST[action] == "newuser") {
  67. $name = $_REQUEST['uname'];
  68. $email = $_REQUEST['email'];
  69. $error = FALSE;
  70. if ($_REQUEST[action] == "newuser" && !$_REQUEST['uname']) {
  71. $message .= "<div align='center'>You must enter a Name.<br /></div>";
  72. $error = TRUE;
  73. }
  74. if (!$_REQUEST['email'] || !ereg("@", $_REQUEST['email'])) {
  75. $message .= "<div align='center'>You must enter a valid email address.<br /></div>";
  76. $error = TRUE;
  77. }
  78. foreach ($cfg[visitor_email_excludes] as $visitor_email_exclude) {
  79. if ($exclude = ereg($visitor_email_exclude, $email)) {
  80. if ($_REQUEST[action] == "send") {
  81. $message = "<div align='left'>You cannot reset your $cfg[inst_name] account password here.<br /></div>";
  82. if ($cfg['auth_help_on']) $message .= "<br />(".$cfg[auth_help].")<br /><br />";
  83. } else {
  84. $message = "You cannot register your $cfg[inst_name] account here.<br /></div>";
  85. if ($cfg['auth_help_on']) $message .= "<br />(".$cfg[auth_help].")<br /><br />";
  86. }
  87. $id = 0;
  88. $error = TRUE;
  89. break;
  90. }
  91. }
  92. $id = db_get_value("user","user_id","user_email='".addslashes($email)."'");
  93. if ($id) $authtype = db_get_value("user", "user_authtype", "user_id = '".addslashes($id)."'");
  94. if ($id && $authtype != "db") {
  95. $error=TRUE;
  96. $message = "<div align='left'>This user account is not authenticated by Segue and so you cannot reset this account's password here.<br /></div>";
  97. }
  98. /******************************************************************************
  99. * a matching user was found and email not excluded
  100. ******************************************************************************/
  101. if ($id > 0 && $error != TRUE) {
  102. if ($_REQUEST[action] == "send") {
  103. $obj =& new user();
  104. $obj->fetchUserID($id);
  105. $obj->randpass(5,3);
  106. $obj->updateDB();
  107. $obj->sendemail(1);
  108. $message = "<div align='left'>A new random password has been sent to the email address you entered above.<br /></div>";
  109. } else {
  110. $message = "<div align='left'>Your email address is already in our database.<br /></div>";
  111. //$message .= " (<a href='passwd.php?$sid&amp;action=reset&amp;email=$email'>Forgot your password?</a>).</div>";
  112. }
  113. /******************************************************************************
  114. * reset password (send) no matching user found ...
  115. ******************************************************************************/
  116. } else if ($_REQUEST[action] == "send" && $error != TRUE) {
  117. $message = "<div align='center'>There is no visitor user account for this email address...<br /></div>";
  118. /******************************************************************************
  119. * register -> newuser: no matching user found therefore create new user
  120. * and authenticate
  121. ******************************************************************************/
  122. } else if ($_REQUEST[action] == "newuser" && $error != TRUE) {
  123. $name = $email;
  124. $obj =& new user();
  125. $obj->uname = $_REQUEST['email'];
  126. $obj->fname = $_REQUEST['uname'];
  127. $obj->email = $_REQUEST['email'];
  128. $obj->type = "visitor";
  129. $obj->authtype = 'db';
  130. $obj->randpass(5,3);
  131. $obj->insertDB();
  132. $obj->sendemail();
  133. $visitor_id = lastid();
  134. $message = "Thank you for registering. Your user account information has been emailed to you. Use this information to log into Segue.<br /><br />";
  135. $message .= "<div align='center'><input type='button' value='Return' onclick='refreshParent()' /></div><br />";
  136. }
  137. /******************************************************************************
  138. * log in -> auth
  139. ******************************************************************************/
  140. } else if ($_REQUEST[action] == "auth") {
  141. $name = $_REQUEST['uname'];
  142. $pass = $_REQUEST['password'];
  143. $valid = 0;
  144. foreach ($_auth_mods as $_auth) {
  145. $func = "_valid_".$_auth;
  146. //print "<br />AUTH: trying ".$_auth ."..."; //debug
  147. if ($x = $func($name,$pass)) {
  148. $valid = 1;
  149. break;
  150. }
  151. }
  152. if ($valid) {
  153. $_SESSION[luser] = $x[user];
  154. $_SESSION[lemail] = $x[email];
  155. $_SESSION[lfname] = $x[fullname];
  156. $_SESSION[ltype] = $x[type];
  157. $_SESSION[lid] = $x[id];
  158. $_SESSION[lmethod] = $x[method];
  159. $_SESSION[auser] = $x[user];
  160. $_SESSION[aemail] = $x[email];
  161. $_SESSION[afname] = $x[fullname];
  162. $_SESSION[atype] = $x[type];
  163. $_SESSION[aid] = $x[id];
  164. $_SESSION[amethod] = $x[method];
  165. $message = "<div align='left'>Your login information was correct. Use the Return button below to complete authentication.<br /><br /></div>";
  166. $message .= "<div align='center'><input type='button' value='Return' onclick='refreshParent()' /></div>";
  167. } else {
  168. $message = "<div align='left'>Your password/username was incorrect.</div>";
  169. }
  170. }
  171. ?>
  172. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  173. <html>
  174. <head>
  175. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  176. <title>
  177. <?
  178. if ($_REQUEST[action] == "reset" || $reset) {
  179. print "Reset Password";
  180. } else if ($_REQUEST[action] == "login" || $auth) {
  181. print "Log In";
  182. } else if ($_REQUEST[action] == "register" || $newuser) {
  183. print "Register";
  184. } else if ($_REQUEST[action] == "change" || $change) {
  185. print "Change My Password";
  186. }
  187. ?>
  188. </title>
  189. <? include("themes/common/logs_css.inc.php"); ?>
  190. <script type='text/javascript'>
  191. // <![CDATA[
  192. function refreshParent() {
  193. window.opener.location.href = window.opener.location.href;
  194. if (window.opener.progressWindow) {
  195. window.opener.progressWindow.close();
  196. }
  197. window.close();
  198. }
  199. // ]]>
  200. </script>
  201. </head>
  202. <?
  203. if ($_SESSION[auser] && $auth)
  204. print "<body onload='refreshParent()'>";
  205. else
  206. print "<body onload='document.passform.oldpass.focus()'>";
  207. ?>
  208. <form action="<? echo $PHP_SELF ?>" method='post' name="passform">
  209. <table cellspacing='1' width='100%'>
  210. <tr><th colspan='2'>
  211. <?
  212. if ($_REQUEST[action] == "reset" || $reset) {
  213. print "Forgot My Password";
  214. } else if ($_REQUEST[action] == "login" || $auth) {
  215. print "Log In";
  216. } else if ($_REQUEST[action] == "register" || $newuser) {
  217. print "Visitor Registratoin";
  218. } else if ($_REQUEST[action] == "change" || $change) {
  219. print "Change My Password";
  220. }
  221. ?>
  222. </th></tr>
  223. <?
  224. /******************************************************************************
  225. * User Accounts links
  226. * Login | Forget your Password | Change your Password
  227. ******************************************************************************/
  228. print "<tr><td colspan='2' align='center'>";
  229. print "<br /><div align='center'>";
  230. if ($_REQUEST[action] == "reset" || $reset) {
  231. print "Forgot your password?";
  232. } else {
  233. if ($_SESSION['auser'])
  234. print "<span style='color: #aaa'>Forgot your password?</span>";
  235. else
  236. print "<a href='passwd.php?$sid&amp;action=reset&amp;email=$email'>Forgot your password?</a>";
  237. }
  238. if ($cfg[auth_register_on] == TRUE) {
  239. if ($_REQUEST[action] == "register" || $newuser) {
  240. print " | Register";
  241. } else {
  242. if ($_SESSION['auser'])
  243. print " | <span style='color: #aaa'>Register</span>";
  244. else
  245. print " | <a href='passwd.php?$sid&amp;action=register&amp;email=$email'>Register</a>";
  246. }
  247. }
  248. if ($_REQUEST[action] == "login" || $auth) {
  249. print " | Login";
  250. } else {
  251. if ($_SESSION['auser'])
  252. print " | <span style='color: #aaa'>Login</span>";
  253. else
  254. print " | <a href='passwd.php?$sid&amp;action=login'>Login</a>";
  255. }
  256. if ($_REQUEST[action] == "change" || $change) {
  257. print " | Change your password";
  258. } else {
  259. print " | <a href='passwd.php?$sid&amp;action=change&amp;email=$email'>Change your password</a>";
  260. }
  261. print "</div><br />";
  262. print "</td></tr>";
  263. /******************************************************************************
  264. * Change Password UI
  265. ******************************************************************************/
  266. //printpre ($_SESSION);
  267. if ($_REQUEST[action] == "change" || $change) {
  268. if (!isset($_SESSION[ltype])) {
  269. print "<tr><td colspan='2' align='left'> You must already be authenticated in order to change your password.<br /><br />";
  270. if ($cfg['auth_help_on']) print "(".$cfg[auth_help].")<br /><br />";
  271. print "</td></tr>";
  272. } else if ($_SESSION[amethod] != "db") {
  273. print "<tr><td colspan='2' align='left'>This user account is not authenticated by Segue and so you cannot reset this account's password here.";
  274. if ($cfg['auth_help_on']) print "<br /><br />(".$cfg[auth_help].")<br /><br />";
  275. print "</td></tr>";
  276. } else {
  277. print "<tr><td colspan='2' align='center'> Chose a new password below.<br />";
  278. if ($cfg['auth_help_on'])
  279. print "<br /><div align='left'>(".$cfg[auth_help].")</div><br />";
  280. print "<tr><td> User Name: </td>";
  281. print "<td><input type='text' name='uname' size='30' value='".$_SESSION['auser']."' readonly /></td>";
  282. print "</tr>";
  283. print "<tr><td>Full Name: </td>";
  284. print "<td><input type='text' name='fname' size='30' value='".$_SESSION['afname']."' readonly /></td>";
  285. print "</tr>";
  286. //print "<tr><td>Email Address:</td>";
  287. //print"<td><input type='text' name='email' size='30' value='".$_REQUEST['email']."' readonly /></td> ";
  288. //print"<tr>";
  289. print"<td>Old Password:</td>";
  290. print"<td><input type='password' name='oldpass' size='30' value='".$oldpass."' /></td></tr>";
  291. print"<tr>";
  292. print"<td>New Password:</td>";
  293. print"<td><input type='password' name='newpass1' size='30' value='".$newpass1."' /> <span style='color: #a00'>*</span></td>";
  294. print"</tr>";
  295. print"<tr>";
  296. print"<td>Again:</td>";
  297. print"<td><input type='password' name='newpass2' size='30' value='".$newpass2."' /> <span style='color: #a00'>*</span></td>";
  298. print"</tr>";
  299. print"<tr>";
  300. print"<td colspan='2'><span style='color: #a00'>* Must be 8-200 characters long and not contain any of the following: \" '</span></td>";
  301. print"</tr>";
  302. print"<tr><td colspan='2' align='center'><input type='submit' value='Change password' /><br /><br />";
  303. print"<input type='hidden' name='action' value='newpassword' />";
  304. print"<input type='hidden' name='change' value='1' />";
  305. print "</td></tr>";
  306. }
  307. /******************************************************************************
  308. * Log in UI
  309. ******************************************************************************/
  310. } else if (($_REQUEST[action] == "login" && !$_SESSION['auser']) || $auth) {
  311. print "<tr><td colspan='2' align='left'> Please enter your username and password. <br /><br />";
  312. print "</td><tr><td> User Name: </td>";
  313. print "<td><input type='text' name='uname' size='30' value='' /></td>";
  314. print "<tr><td>Password:</td>";
  315. print"<td><input type='password' name='password' size='30' value='' /> </td>";
  316. print"<tr><td colspan='2' align='center'><input type='submit' value='Log In' /><br /><br />";
  317. print "</td></tr>";
  318. print"<input type='hidden' name='action' value='auth' />";
  319. print"<input type='hidden' name='auth' value='1' />";
  320. /******************************************************************************
  321. * Register UI
  322. ******************************************************************************/
  323. } else if ($_REQUEST[action] == "register" || $newuser) {
  324. print "<tr><td colspan='2' align='left'> Please enter your name and your email address.";
  325. print " Once you have registered you will be able to post to this and all other $cfg[inst_name] public forums.";
  326. print " Your username will be your email address and a password will be emailed to you.<br /><br />";
  327. if ($cfg['auth_help_on'])
  328. print "(".$cfg[auth_help].")<br /><br />";
  329. print "</td><tr><td> Name: </td>";
  330. print "<td><input type='text' name='uname' size='30' value='".$_REQUEST['uname']."' /></td>";
  331. print "<tr><td>Email Address:</td>";
  332. print"<td><input type='text' name='email' size='30' value='".$_REQUEST['email']."' /> </td>";
  333. if (!$newuser || $error == TRUE)
  334. print"<tr><td colspan='2' align='center'><input type='submit' value='Register' /></td></tr>";
  335. print"<input type='hidden' name='action' value='newuser' />";
  336. print"<input type='hidden' name='newuser' value='1' />";
  337. /******************************************************************************
  338. * Reset Password UI
  339. ******************************************************************************/
  340. } else if ($_REQUEST[action] == "reset" || $reset) {
  341. if (isset($_SESSION[amethod]) && $_SESSION[amethod] != "db") {
  342. print "<tr><td colspan='2' align='left'>This user account is not authenticated by Segue and so you cannot reset this account's password here.";
  343. if ($cfg['auth_help_on'])
  344. print "<br /><br />(".$cfg[auth_help].")<br /><br />";
  345. } else {
  346. print "<tr><td colspan='2' align='left'> Please enter your email address and a new password will be sent to you.<br /><br />";
  347. if ($cfg['auth_help_on'])
  348. print "(".$cfg[auth_help].")<br /><br />";
  349. print "</td><tr><td>Email Address:</td>";
  350. print"<td><input type='text' name='email' size='30' value='".$_REQUEST['email']."' /></td></tr>";
  351. print"<tr><td colspan='2' align='center'><input type='submit' name='submit' value='Send new password' /><br /><br />";
  352. print"<input type='hidden' name='action' value='send' />";
  353. print"<input type='hidden' name='reset' value='1' />";
  354. }
  355. }
  356. print "</td></tr>";
  357. print "<tr><td colspan='2'>";
  358. print"<br />";
  359. print $message;
  360. print"<br />";
  361. print"</td></tr>";
  362. print "</table><br />";
  363. //print "<div align='right'><input type='button' value='Close Window' onclick='window.close()' /></div>";
  364. ?>
  365. <?
  366. // debug output -- handy :)
  367. /* print "<pre>"; */
  368. /* print "request:\n"; */
  369. /* print_r($_REQUEST); */
  370. /* print "\n\n"; */
  371. /* print "session:\n"; */
  372. /* print_r($_SESSION); */
  373. /* print "\n\n"; */
  374. /* if (is_object($thisPage)) { */
  375. /* print "\n\n"; */
  376. /* print "thisPage:\n"; */
  377. /* print_r($thisPage); */
  378. /* } else if (is_object($thisSection)) { */
  379. /* print "\n\n"; */
  380. /* print "thisSection:\n"; */
  381. /* print_r($thisSection); */
  382. /* } else if (is_object($thisSite)) { */
  383. /* print "\n\n"; */
  384. /* print "thisSite:\n"; */
  385. /* print_r($thisSite); */
  386. /* } */
  387. /* print "</pre>"; */
  388. ?>