<?php 
 ob_start();
 session_start();
include('dbconnect.php');

if( isset($_POST['login']) ) { 

  $uname = trim($_POST['empid']);
  $uname = strip_tags($uname);
  $uname = htmlspecialchars($uname);
  $uname = mysqli_real_escape_string($uname);
  
  $psw = trim($_POST['password']);
  $psw = strip_tags($psw);
  $psw = htmlspecialchars($psw);
  $psw = mysqli_real_escape_string($psw);

  
  $password = hash('sha256', $psw); 
  
$sql = "SELECT * FROM account WHERE username= ? ";
mysqli_stmt_bind_param($sql, 's' , $uname);
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);
$row = mysqli_fetch_assoc($result);


 if( $count == 1 && $row['password']==$password ) {
  $_SESSION['user'] = $row['EmpID'];
  header("Location: superaddashboard.php");
 }
else{
  echo 'user doesnt exist';
}


}
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">

  <head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>SB Admin - Login</title>

    <!-- Bootstrap core CSS-->
    <link href="../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom fonts for this template-->
    <link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">

    <!-- Custom styles for this template-->
        <link href="../css/sb-admin.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">

  </head>

  <body style="background-image: url('../images/bg.jpg'); display:block;">

    <div class="container">
      <div class="card card-login mx-auto mt-5">
        <div class="card-header">Login</div>
        <div class="card-body">
          <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
            <div class="form-group">
              <div class="form-label-group">
                <input type="text" name="empid" id="inputEmail" class="form-control" placeholder="Enter Employee ID..." required="required" autofocus="autofocus">
                <label for="inputEmail">Employee ID</label>
              </div>
            </div>
            <div class="form-group">
              <div class="form-label-group">
                <input type="password" name="pass" id="inputPassword" class="form-control" placeholder="Enter Password..." required="required">
                <label for="inputPassword">Password</label>
              </div>
            </div>
            <div class="form-group">
              <div class="checkbox">
                <label>
                  <input type="checkbox" value="remember-me">
                  Remember Password
                </label>
              </div>
            </div>
            <button name="login" class="btn btn-primary btn-block" href="index.html">Login</button>
          </form>
    
        </div>
      </div>
    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="../vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="../vendor/jquery-easing/jquery.easing.min.js"></script>

          <script language="javascript" type="text/javascript">
            $(document).ready(function(){
            $("form").on("submit", function(){
                $("#pageloader").fadeIn();
            });//submit

             $('#preloader').fadeOut();
            });//document ready



        </script>
</body>

</html>
