 <?php 

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
error_reporting(0);
session_start(); 
include_once 'config.php';
require 'link.php';
if(isset($_POST['submit']))
  {
  $name=$_POST['name'];
  $password=$_POST['password'];
  //$pass= password_hash($password,PASSWORD_BCRYPT);
  $email_search="SELECT * FROM User_Reg_tbl WHERE `name`='$name'";
  $query=mysqli_query($con,$email_search) or die(mysqli_error($con));
  $email_count=mysqli_num_rows($query);
  if($email_count){
      $email_pass=mysqli_fetch_assoc($query);
      $db_pass=$email_pass['password'];
      $_SESSION['name']=$email_pass['name'];
      $_SESSION['password']=$email_pass['password'];
      $_SESSION['fullname']=$email_pass['fullname'];
      if($password == $db_pass){
          $m_name = gethostname();
          $m_ip =  getHostByName(getHostName());
          $nameemp= $_SESSION['name'];
          date_default_timezone_set('Asia/Kolkata');
          $Login_time =  date('Y-m-d H:i:s');
         
          $sql="UPDATE user_reg_tbl SET login_time ='$Login_time' , machine_name = '$m_name' , machine_ip = '$m_ip' , state='1' where name = '$nameemp'";
          $query1=mysqli_query($con,$sql) or die(mysqli_error($con));
          $_SESSION['login_time']=$Login_time;
       
          ?>
         <script>
                 swal("Login Successful",
                   "Have a great day ahead",
                      "success",
                      {
                         dangerMode: true,
                         buttons: false,
                         closeOnClickOutside: true,
                         timer:1000,
                                     })
                                     .then(function() {
                               window.location = "home.php";
                            
                      });
          </script>
    <?php
      }else{
          ?>
          <script>
                     swal("Incorrect Password",
                   "Please Enter Correct Password",
                      "warning",
                      {
                         dangerMode: true,
                         buttons: false,
                         closeOnClickOutside: true,
                         timer:1000,
                                     })
                                     .then(function() {
                               window.location = "index.php";
                            
                      });
          </script>
              <?php
      }
  }
  else{
      ?>
              <script>             
             swal("Invalid Email",
                   "Please Enter Valid EmailId",
                      "warning",
                      {
                         dangerMode: true,
                         buttons: false,
                         closeOnClickOutside: true,
                         timer:1000,
                                     })
                                     .then(function() {
                               window.location = "index.php";
                            
                      });
          </script>
              <?php
  }
}
?>
<!DOCTYPE html>

<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Emp_Prod_Benchmark</title>
    <link rel="shortcut icon" href="images/Files_Download.png" type="image/x-icon"/>
    <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
    <link href="vendor/twbs/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
    <!-- <script type="text/javascript" src="bootstrap-4.3.1-dist/sweetalert.min.js_2.1.0/cdnjs/sweetalert.min.js"></script>	 -->
    <script src="jquery_3.2.1.slim.min.js"></script>
    <script src="vendor/components/jquery/jquery.min.js"></script>
    <script src="vendor/twbs/bootstrap/dist/js/bootstrap.min.js"></script>

</head>
<style>
    body {

display: flex;

justify-content: center;

align-items: center;

height: 100vh;

flex-direction: column;

}

*{

font-family: cursive;

box-sizing: padding-box;

}



h2 {
color: black;

text-align: center;

margin-bottom: 40px;

}

input.input
{
 border:none;
 border-bottom: 2px solid black;
 transition: 0.4s;
 /* color:greenyellow;        */
}
input.input:focus
{
    border:none;
    border-bottom: 2px solid orange;
    transition: 2s;
    box-shadow: none;
}

label {

color: #0c0101;

font-size: 18px;

padding: 10px;

}

button.btn
{
    border-radius:15px;
}

i.fas
{
    
    border: 2px solid Orange;
    border-radius:75%;
    padding:12px;
}

.error {

background: #F2DEDE;

color: #0c0101;

padding: 10px;

width: 95%;

border-radius: 5px;

margin: 20px auto;

}

h1 {

text-align: center;


}

</style>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-4"></div>
        <div class="col-md-4">
        <img class="p-4" src="images/Final_logo.png" alt="brand" style="height:175px;width:100%;margin-top:-80px" >

        <form class="" action="" method="post" autocomplete="off">
<br>            <!-- <img class="px-2" src="images/Final_logo.png" alt="brand" style="height:150px;width:100%" > -->
            <center><h3 class="form-icon"><i class="fas fa-users"></i> Login</h3></center>

            <?php if (isset($_GET['error'])) { ?>

            <p class="error"><?php echo $_GET['error']; ?></p>

            <?php } ?>
<br>
            <input class="form-control input" type="text" name="name" placeholder="User Name" value="<?php echo $_SESSION['name']; ?>" autofocus><br>

            <input type="password" class=" form-control input" name="password" placeholder="Password" ><br> 

            <button type="submit" name="submit" class="btn btn-sm btn-warning btn-block" style="font-weight:500;font-size:16px;">Login</button>

            </form>
            <br>
            <br>
            Please contact Admin for Credentials  !!! 
        </div>
                    <div class="col-md-4"></div>
                </div>

            </div>
     

</body>
</html>