<?php
include('config/setup.php');
session_start();
    if(isset($_POST['login'])){
        $username = $config->real_escape_string($_POST['username']);
        $password = $config->real_escape_string($_POST['password']);
        $_SESSION['tmp_name'] = $username;
        // $_SESSION['tmp_pass'] = $password;
        $sql = "SELECT * FROM master_login WHERE Master_Username = '$username' AND Master_Type = 1 "; 
        $res = $config->query($sql);
        if($res->num_rows > 0){
            $row = $res->fetch_assoc();
            $pass = $row['Master_Password'];
            if(password_verify($password,$pass)){
                if( $row['Master_Active_Status'] == 1){
                    $_SESSION['user_id'] = $row['Master_id'];
                    header('Location:Main/dashboard.php');
                }else{
                    $_SESSION['err'] = "Your Login is Locked" ;
                }
            }else{
                $_SESSION['err'] = "Invalid password" ;
            }
        }else{
            $_SESSION['err'] = "Invalid username" ;
        }
    }


?>

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin | Login</title>
    
    <!-- Google Font: Source Sans Pro -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="assets/login/plugins/fontawesome-free/css/all.min.css">
    <!-- icheck bootstrap -->
    <link rel="stylesheet" href="assets/login/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="assets/login/dist/css/adminlte.min.css">
</head>
<body class="hold-transition login-page">
    <div class="login-box">
        <div class="login-logo">
            <b>Admin</b>
        </div>
        <!-- /.login-logo -->
         <div class="card">
            <div class="card-body login-card-body">
                <p class="login-box-msg">Sign in to start your session</p>
                <form action="index.php" method="post">
                    <div class="input-group mb-3">
                        <input type="email" class="form-control" placeholder="Enter your Username" name="username" value="<?php	if(isset($_SESSION['tmp_name'])){ echo $_SESSION['tmp_name'] ; unset($_SESSION['tmp_name']); } ?>">
                        <div class="input-group-append">
                            <div class="input-group-text">
                                <span class="fas fa-envelope"></span>
                            </div>
                        </div>
                    </div>
                    <div class="input-group mb-3">
                        <input type="password" class="form-control" placeholder="Enter your Password" name="password" >
                        <div class="input-group-append">
                            <div class="input-group-text">
                                <span class="fas fa-lock"></span>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <!-- /.col -->
                        <div class="col-12">
                            <button type="submit" class="btn btn-primary btn-block" name="login">Login</button>
                        </div> 
                        <!-- /.col -->
                     </div>
                    <?php	if(isset($_SESSION['err']) && !empty($_SESSION['err'])){ ?>
                	<span class="text-danger"><?= $_SESSION['err'] ?></span>
                	<?php unset($_SESSION['err']); } ?>
                </form>
            </div>
        <!-- /.login-card-body -->
        </div>
    </div>
    <!-- /.login-box -->

<!-- jQuery -->
<script src="assets/login/ plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="assets/login/ plugins/bootstr bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="assets/login/ di adminlte.min.js"></script>
</body>
</html>
