Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_POST['username']) && isset($_POST['password']))
- {
- $conn = pg_connect("host=127.0.0.1 dbname=worktest user=worktestuser password=100585400");
- $username = trim($_POST['username']);
- $password = trim($_POST['password']);
- $loginQuery = "SELECT * FROM users WHERE username='$username' AND password='$password'";
- $loginResult = pg_query($conn, $loginQuery);
- if(pg_num_rows($loginResult) > 0)
- {
- $accessLevelQuery = "SELECT username, accessLevel FROM users WHERE username='$username'";
- $accessLevelResult = pg_query($conn, $accessLevelQuery);
- while($row=pg_fetch_assoc($accessLevelResult))
- {
- if ($row['accessLevel']=='1')
- {
- echo "Access 1";
- }
- elseif ($row['accessLevel']=='2')
- {
- echo "Access 2";
- }
- else
- {
- echo "Access denied";
- }
- }
- }
- else
- {
- echo "ERROR: Username/password not found in database.";
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>Login Page</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="./css/bootstrap.min.css">
- <link rel="stylesheet" href="./css/login.css">
- <script src="./js/bootstrap.min.js"></script>
- </head>
- <body class="text-center">
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
- <img class="mb-4" src="./img/loginimg.png" alt="" width="72" height="72">
- <h1 class="h3 mb-3 font-weight-normal">Login</h1>
- <label for="usernameLabel" class="sr-only">Username</label>
- <input type="text" id="usernameLabel" name="username" class="form-control" placeholder="Username" required autofocus>
- <label for="passwordLabel" class="sr-only">Password</label>
- <input type="password" id="passwordLabel" name="password" class="form-control" placeholder="Password" required>
- <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement