changepassword.php 1002 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. session_start();
  3. if (!isset($_SESSION['login'])){
  4. header('Location: signin.php');
  5. exit();
  6. }
  7. if ($_SERVER['REQUEST_METHOD'] != 'POST') {
  8. header('Location: signin.php');
  9. exit();
  10. }
  11. if (!isset($_POST['passwd'], $_POST['passwdconf'])) {
  12. header('Location: signin.php');
  13. exit();
  14. }
  15. if (empty($_POST['passwd']) || empty($_POST['passwdconf'])) {
  16. header('Location: signin.php');
  17. exit();
  18. }
  19. $passwd = htmlspecialchars($_POST['passwd']);
  20. $passwdconf = htmlspecialchars($_POST['passwdconf']);
  21. if ($passwd != $passwdconf) {
  22. header('Location: signin.php');
  23. exit();
  24. }
  25. try {
  26. $user = new User($_SESSION['login'], $passwd);
  27. $user->changePassword();
  28. header('Location: welcome.php');
  29. exit();
  30. }
  31. catch (Exception $e) {
  32. $_SESSION['message'] = $e->getMessage();
  33. header('Location: signin.php');
  34. exit();
  35. }