authenticate.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. session_start();
  3. include_once('bdd.php');
  4. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  5. $login = htmlspecialchars($_POST['login']);
  6. $passwd = htmlspecialchars($_POST['passwd']);
  7. try {
  8. $pdo = new PDO(SQL_DSN, SQL_USERNAME, SQL_PASSWORD);
  9. }
  10. catch(PDOException $e) {
  11. $_SESSION['message'] = $e->getMessage();
  12. header('Location: signin.php');
  13. exit();
  14. }
  15. $req = $pdo->prepare('SELECT passwd from Users WHERE login = :login');
  16. $req->bindValue(':login', $login, PDO::PARAM_STR);
  17. $req->execute();
  18. $count = $req->rowCount();
  19. if ($count == 0) {
  20. header('Location: signin.php');
  21. exit();
  22. }
  23. foreach ($req as $row) {
  24. if (!password_verify($passwd, $row['passwd'])) {
  25. header('Location: signin.php');
  26. $_SESSION['message'] = 'Bad password';
  27. exit();
  28. }
  29. }
  30. $_SESSION['login'] = $login;
  31. header('Location: welcome.php');
  32. } else {
  33. header('Location: signin.php');
  34. }