login.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <div class="container">
  2. <div class="textContainer">
  3. <p>
  4. You probably do not want to log in here. You cannot create any
  5. account here, an admin must do this for you. There is not really
  6. much to see either.
  7. </p>
  8. <p>
  9. Anyway here is the login form.
  10. </p>
  11. <form action="index.php?section=login" method="POST">
  12. <p>
  13. <div class="inputName">username</div>
  14. <input class="inputForm" name="user">
  15. </p>
  16. <p>
  17. <div class="inputName">password</div>
  18. <input class="inputForm" name="password" type="password">
  19. </p>
  20. <p>
  21. <input class="submitForm" type="submit" value="login">
  22. </p>
  23. </form>
  24. <?php
  25. if(session_status() == PHP_SESSION_NONE)
  26. {
  27. session_start();
  28. }
  29. if(isset($_POST["user"]))
  30. {
  31. $username = filter_input(INPUT_POST, "user");
  32. $password = filter_input(INPUT_POST, "password");
  33. require_once('database.php');
  34. $db_connection = new databank();
  35. $db_connection->connect();
  36. if($db_connection->isConnected())
  37. {
  38. $user = $db_connection->getUser($username, $password);
  39. if($user != null)
  40. {
  41. $_SESSION["user"] = $user->username;
  42. if($user->admin)
  43. {
  44. $_SESSION["admin"] = true;
  45. }
  46. header("Location: index.php");
  47. }
  48. else
  49. {
  50. echo "There is no account with this credentials.";
  51. }
  52. }
  53. $db_connection->disconnect();
  54. // hash with password_hash($password, PASSWORD_DEFAULT))
  55. /*if($user == "kajetan" && password_verify($password, '$2y$10$LT4rMKf81UNRlfpKdLHVVOC9IKGrZehg9qqhkJoEMjvmtyubRYtoK'))
  56. {
  57. $_SESSION["user"] = user;
  58. header("Location: index.php");
  59. }*/
  60. }
  61. ?>
  62. </div>
  63. </div>