change_password.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Change password functionality
  4. */
  5. class ChangePassword
  6. {
  7. public function dispatch()
  8. {
  9. //print_r($_SERVER);
  10. if (empty($_GET['v'])) {
  11. return $this->renderError('General error');
  12. }
  13. $key = $_GET['v'];
  14. $real_key = sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR']);
  15. $key_sha1 = substr($key, 0, 10) . substr($key, 20, strlen($key));
  16. $stamp = substr($key, 10, 10);
  17. $allowed = time() - 60 * 5; // - 5 mins
  18. if (strcmp($real_key, $key_sha1) != 0) {
  19. return $this->renderError('Invalid keys');
  20. }
  21. /*if ($stamp < $allowed) {
  22. return $this->renderError('Key is expired');
  23. }*/
  24. $this->showResetForm();
  25. print $key_sha1 . "<br />" . $real_key;
  26. }
  27. public function showResetForm()
  28. {
  29. print <<<HTML
  30. <form action="" >
  31. <input type="hidden" name="action" value="change" />
  32. <label>Enter secret code:</label>
  33. <input type="text" name="secret_code" value="" />
  34. <label>Enter new password:</label>
  35. <input type="text" name="secret_code" value="" />
  36. </form>
  37. HTML;
  38. }
  39. public function renderError($message)
  40. {
  41. print <<<HTML
  42. {$message}
  43. HTML;
  44. }
  45. }
  46. $changePassword = new ChangePassword();
  47. $changePassword->dispatch();
  48. ?>