changepassword.php 1.0 KB

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