Advertisement
Guest User

Untitled

a guest
Aug 15th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. <?php
  2.  
  3. if (isset($_POST['username']) && isset($_POST['password']))
  4. {
  5. $conn = pg_connect("host=127.0.0.1 dbname=worktest user=worktestuser password=100585400");
  6. $username = trim($_POST['username']);
  7. $password = trim($_POST['password']);
  8. $loginQuery = "SELECT * FROM users WHERE username='$username' AND password='$password'";
  9. $loginResult = pg_query($conn, $loginQuery);
  10.  
  11. if(pg_num_rows($loginResult) > 0)
  12. {
  13. $accessLevelQuery = "SELECT username, accessLevel FROM users WHERE username='$username'";
  14. $accessLevelResult = pg_query($conn, $accessLevelQuery);
  15. while($row=pg_fetch_assoc($accessLevelResult))
  16. {
  17. if ($row['accessLevel']=='1')
  18. {
  19. echo "Access 1";
  20. }
  21. elseif ($row['accessLevel']=='2')
  22. {
  23. echo "Access 2";
  24. }
  25. else
  26. {
  27. echo "Access denied";
  28. }
  29. }
  30. }
  31. else
  32. {
  33. echo "ERROR: Username/password not found in database.";
  34. }
  35. }
  36.  
  37. ?>
  38. <!DOCTYPE html>
  39. <html lang="en">
  40. <head>
  41. <title>Login Page</title>
  42. <meta charset="utf-8">
  43. <meta name="viewport" content="width=device-width, initial-scale=1">
  44. <link rel="stylesheet" href="./css/bootstrap.min.css">
  45. <link rel="stylesheet" href="./css/login.css">
  46. <script src="./js/bootstrap.min.js"></script>
  47. </head>
  48.  
  49. <body class="text-center">
  50. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
  51. <img class="mb-4" src="./img/loginimg.png" alt="" width="72" height="72">
  52. <h1 class="h3 mb-3 font-weight-normal">Login</h1>
  53. <label for="usernameLabel" class="sr-only">Username</label>
  54. <input type="text" id="usernameLabel" name="username" class="form-control" placeholder="Username" required autofocus>
  55. <label for="passwordLabel" class="sr-only">Password</label>
  56. <input type="password" id="passwordLabel" name="password" class="form-control" placeholder="Password" required>
  57. <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
  58. </form>
  59. </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement