Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require("header.php");
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- if (isset($_POST['username']) && isset($_POST['password'])) {
- $username = $_POST['username'];
- $password = $_POST['password'];
- if (preg_match("/^[A-Z][a-z]+\s[A-Z][a-z]+$/", $username) && preg_match("/^[\w]{6,}$/", $password)) {
- $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
- $result = $Conn->query($query);
- $count = mysqli_num_rows($result);
- if ($count == 1) {
- while($row = $result->fetch_assoc()) {
- if ($row['active'] == 1) {
- $user = $username;
- $ip = $_SERVER['REMOTE_ADDR'];
- $query2 = "INSERT INTO logs (user, ip, type, target, text) VALUES ('$user', '$ip', 'login', 'system', 'Logged in.')";
- $result2 = $Conn->query($query2);
- $_SESSION['username'] = $username;
- $_SESSION['id'] = $row['id'];
- } elseif ($row['active'] == 0) {
- $Error = "Account not verified. Contact system admin to be verified.";
- } elseif ($row['active'] == -1) {
- $Error = "Account deactivated. Contact system admin to be reactivated.";
- }
- }
- } else {
- $Error = "Invalid username or password.";
- }
- } else {
- $Error = "Invalid username or password.";
- }
- }
- }
- if (isset($_SESSION['username'])) {
- header('Location: index.php');
- }
- ?>
- <div class="container">
- <form class="form-signin" method="post">
- <h2 class="form-signin-heading">Admin Panel <small>Sign In</small></h2>
- <label for="username" class="sr-only">Username</label>
- <input type="text" name="username" id="username" class="form-control" placeholder="Username" required autofocus>
- <label for="password" class="sr-only">Password</label>
- <input type="password" name="password" id="password" class="form-control" placeholder="Password" required>
- <?php if (isset($Error)) echo "<div class=\"alert alert-danger\" style=\"margin-bottom:0px;\" role=\"alert\">$Error</div><br>"; ?>
- <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
- <input type="hidden" id="loginAttempted" value="beepboop">
- </form>
- <form class="form-signin" action="register.php">
- <button class="btn btn-lg btn-secondary btn-block btn-sm" type="submit">Register</button>
- </form>
- </div> <!-- /container -->
- <?php
- require("footer.php");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement