Advertisement
Guest User

Untitled

a guest
Sep 30th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <?php session_start(); ?>
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta charset="utf-8">
  6. <title></title>
  7. <?php include "includes.php"; ?>
  8. </head>
  9. <body>
  10. <?php include "header.php" ?>
  11. <br />
  12. <div class = "container">
  13. <form class = "form-signin" method="post">
  14. <input type="text" class="form-control" name="username" placeholder="Администраторско име" required></br>
  15. <input type="password" class="form-control" name="password" placeholder="Парола" required> <br />
  16. <button class="form-control" type="submit" name="login">Влез</button>
  17. </form>
  18. </div>
  19. </body>
  20. </html>
  21. <?php
  22. //Start creating admin user login functionality
  23. if (isset($_POST['login'])) {
  24.  
  25. $username = $_POST['username'];
  26. $password = $_POST['password'];
  27.  
  28. //Check if inputs are empty
  29. if (empty($username) || empty($password)) {
  30. header("Location: index.php?login=empty");
  31. exit();
  32. } else {
  33. $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
  34. $result = mysqli_query($conn, $sql);
  35. $resultCheck = mysqli_num_rows($result);
  36.  
  37. if ($resultCheck < 1) {
  38. header("Location: index.php?login=error");
  39. exit();
  40. } else {
  41. if ($row = mysqli_fetch_assoc($result)) {
  42. //De-hashing the password
  43. $hashedPasswordCheck = password_verify($password, $row['password']);
  44. if ($hashedPasswordCheck == false) {
  45. header("Location: index.php?login=error");
  46. exit();
  47. } elseif ($hashedPasswordCheck == true) {
  48. //Log in the admin user here
  49. $_SESSION['usernameId'] = $row['id'];
  50. $_SESSION['username'] = $row['username'];
  51. header("Location: index.php?login=success");
  52. exit();
  53. }
  54. }
  55. }
  56. }
  57. } else {
  58. header("Location: index.php?login=error");
  59. exit();
  60. }
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement