You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.9 KiB
PHP
92 lines
2.9 KiB
PHP
<?php
|
|
// Initialize the session
|
|
session_start();
|
|
|
|
|
|
|
|
// Check if the user is already logged in, if yes then redirect him to welcome page
|
|
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
|
|
header("location: index.php");
|
|
exit;
|
|
}
|
|
|
|
// Include config file
|
|
require_once "model/db.php";
|
|
|
|
// Define variables and initialize with empty values
|
|
$username = $password = "";
|
|
$username_err = $password_err = $login_err = "";
|
|
|
|
|
|
// Processing form data when form is submitted
|
|
if($_SERVER["REQUEST_METHOD"] == "POST"){
|
|
|
|
// Check if username is empty
|
|
if(empty(trim($_POST["username"]))){
|
|
$username_err = "Please enter username.";
|
|
} else{
|
|
$username = trim($_POST["username"]);
|
|
}
|
|
|
|
// Check if password is empty
|
|
if(empty(trim($_POST["password"]))){
|
|
$password_err = "Please enter your password.";
|
|
} else{
|
|
$password = trim($_POST["password"]);
|
|
}
|
|
|
|
// Validate credentials
|
|
if(empty($username_err) && empty($password_err)){
|
|
if($username == "pseudoRoot"){
|
|
if($password == "nemamheslo"){
|
|
|
|
session_start();
|
|
$_SESSION["loggedinAdmin"] = true;
|
|
$_SESSION["username"] = "admin";
|
|
header("location: controller/insertWhat.php");
|
|
} else $login_err = "Wrong Password";
|
|
} else $login_err = "Wrong Username";
|
|
}else $login_err = "You didnt Enter either username of Password";
|
|
|
|
unset($pdo);
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Admin Login</title>
|
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
|
<style>
|
|
body{ font: 14px sans-serif; }
|
|
.wrapper{ width: 360px; padding: 20px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="wrapper">
|
|
<h2>SECRET ADMIN LOGIN???</h2>
|
|
<?php
|
|
if(!empty($login_err)){
|
|
echo '<div class="alert alert-danger">' . $login_err . '</div>';
|
|
}
|
|
?>
|
|
|
|
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
|
|
<div class="form-group">
|
|
<label>ADMIN name</label>
|
|
<input type="text" name="username" class="form-control <?php echo (!empty($username_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $username; ?>">
|
|
<span class="invalid-feedback"><?php echo $username_err; ?></span>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Password</label>
|
|
<input type="password" name="password" class="form-control <?php echo (!empty($password_err)) ? 'is-invalid' : ''; ?>">
|
|
<span class="invalid-feedback"><?php echo $password_err; ?></span>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="submit" class="btn btn-primary" value="Login">
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>
|