PageRenderTime 25ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/reset_password.php

https://github.com/davidma/ICRO-Web-Tool
PHP | 88 lines | 69 code | 16 blank | 3 comment | 11 complexity | 532a5f102e713a5b80d1fee58a0c18bc MD5 | raw file
  1. <?php
  2. // Start the page
  3. require("template/header.php");
  4. echo "<div class='newsbox'>";
  5. echo "<div class='newstitle'>Modify a user</div>";
  6. echo "<div class='newscontent'>";
  7. // If its a non-logged in user, display public text
  8. if (!$theSentry->login())
  9. {
  10. echo "You need to be logged in to view this page";
  11. }
  12. else
  13. {
  14. if ($theSentry->hasPermission(2))
  15. {
  16. if (isset($_POST['user_id']))
  17. {
  18. $characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  19. $pw_random = "";
  20. for ($p = 0; $p < 12; $p++)
  21. {
  22. $pw_random .= $characters[mt_rand(0, strlen($characters))];
  23. }
  24. $password = sha1($pw_random);
  25. $insert = "update users set password = '$password' where user_id = '".$_POST['user_id']."';";
  26. $result = $theDB->doQuery($insert);
  27. if (!result)
  28. {
  29. print 'Error adding user to DB - '.$theDB->lasterror().' - <a href="user_add.php">try again?</a>';
  30. }
  31. else
  32. {
  33. $res = $theDB->fetchQuery("select * from users where user_id = '".$_POST['user_id']."';");
  34. $to = $res[0]['email'];
  35. $subject = "[ICRO] Password Reset for Website";
  36. $from = "ICRO Mailer <no-reply@icro.ie>";
  37. $headers = "From: $from";
  38. $url = "http://www.icro.ie/";
  39. $message = "Hello ".$res[0]['first_name'].",\n\nYour password has been reset for $url\nYou can now log in with the following details:\n\nUsername: ".$res[0]['username']."\nPassword: ".$pw_random."\n\nOnce you log in, you can change your password from the main menu page. Please take a moment to ensure the rest of your profile details (especially mobile phone) are correct - these will be used in the event of a callout.\n\nHave a good day!,\n\nICRO Web Team";
  40. mail($to,$subject,$message,$headers);
  41. $theLogger->log("Password reset for user ".$res[0]['username']." and email sent");
  42. echo "Password changed for user - email sent to ".$res[0]['email']."<br/>";
  43. }
  44. }
  45. else
  46. {
  47. echo "Select a User to modify:<br/><br/>";
  48. echo "<form action='reset_password.php' method='post'>";
  49. $res = $theDB->fetchQuery("select user_id,first_name,last_name from users order by last_name;");
  50. if (!$res)
  51. {
  52. echo "No Users found!";
  53. die();
  54. }
  55. else
  56. {
  57. echo "<select name=user_id>";
  58. for ($i=0; $i<count($res); $i++)
  59. {
  60. echo "<option value='".$res[$i]['user_id']."'>".$res[$i]['last_name'].", ".$res[$i]['first_name']."</option>";
  61. }
  62. echo "</select>";
  63. }
  64. echo "<INPUT TYPE='submit' onClick='javascript:return confirm('Are you sure you want to reset this users password?')' value='Reset Password'/>";
  65. echo "</form>";
  66. }
  67. }
  68. }
  69. // End the page
  70. echo "<div id='clear_both' style='clear:both;'></div></div>";
  71. require("template/footer.html");
  72. ?>