login.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. require dirname(__DIR__) . '/app/bootstrap.php';
  3. session_boot();
  4. if (auth_check()) {
  5. redirect('index.php');
  6. }
  7. $error = null;
  8. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  9. csrf_verify();
  10. $lock = auth_locked_for();
  11. if ($lock > 0) {
  12. $error = 'Too many failed attempts. Try again in ' . ceil($lock / 60) . ' min.';
  13. } elseif (auth_attempt((string)($_POST['username'] ?? ''), (string)($_POST['password'] ?? ''))) {
  14. redirect('index.php');
  15. } else {
  16. $lock = auth_locked_for();
  17. $error = $lock > 0
  18. ? 'Too many failed attempts. Try again in ' . ceil($lock / 60) . ' min.'
  19. : 'Invalid username or password.';
  20. }
  21. }
  22. ?><!DOCTYPE html>
  23. <html lang="en">
  24. <head>
  25. <meta charset="utf-8">
  26. <meta name="viewport" content="width=device-width, initial-scale=1">
  27. <title>Admin login</title>
  28. <link rel="stylesheet" href="../assets/site.css">
  29. </head>
  30. <body class="admin">
  31. <div class="login-wrap"><div class="login-card">
  32. <h1>Backoffice</h1>
  33. <?php if ($error): ?><div class="flash flash-error" style="margin-top:1.2rem"><?= e($error) ?></div><?php endif; ?>
  34. <form method="post">
  35. <?= csrf_field() ?>
  36. <label for="u">Username</label>
  37. <input type="text" id="u" name="username" autofocus autocomplete="username">
  38. <label for="p">Password</label>
  39. <input type="password" id="p" name="password" autocomplete="current-password">
  40. <button type="submit" style="width:100%">Log in</button>
  41. </form>
  42. </div></div>
  43. </body>
  44. </html>