Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start(); ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- <?php include "includes.php"; ?>
- </head>
- <body>
- <?php include "header.php" ?>
- <br />
- <div class = "container">
- <form class = "form-signin" method="post">
- <input type="text" class="form-control" name="username" placeholder="Администраторско име" required></br>
- <input type="password" class="form-control" name="password" placeholder="Парола" required> <br />
- <button class="form-control" type="submit" name="login">Влез</button>
- </form>
- </div>
- </body>
- </html>
- <?php
- //Start creating admin user login functionality
- if (isset($_POST['login'])) {
- $username = $_POST['username'];
- $password = $_POST['password'];
- //Check if inputs are empty
- if (empty($username) || empty($password)) {
- header("Location: index.php?login=empty");
- exit();
- } else {
- $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
- $result = mysqli_query($conn, $sql);
- $resultCheck = mysqli_num_rows($result);
- if ($resultCheck < 1) {
- header("Location: index.php?login=error");
- exit();
- } else {
- if ($row = mysqli_fetch_assoc($result)) {
- //De-hashing the password
- $hashedPasswordCheck = password_verify($password, $row['password']);
- if ($hashedPasswordCheck == false) {
- header("Location: index.php?login=error");
- exit();
- } elseif ($hashedPasswordCheck == true) {
- //Log in the admin user here
- $_SESSION['usernameId'] = $row['id'];
- $_SESSION['username'] = $row['username'];
- header("Location: index.php?login=success");
- exit();
- }
- }
- }
- }
- } else {
- header("Location: index.php?login=error");
- exit();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement