<?php
error_reporting(0);
include '../config.php';
include '../fungsi.php';
include '../Hash.php';
extract($_POST);

if(isset($reset)){
   
    echo "";
    $pass = mysqli_real_escape_string($con,$pass);
    
	if(mysqli_num_rows(mysqli_query($con,"select id from akunn where pin='$pass'"))){
	    
	    $options = [
            'cost' => 10,
        ];
        
	    $newpass = randomString(10);
	    //$hashpass = create_hash($newpass);
	    $hashpass = password_hash($newpass,PASSWORD_DEFAULT,$options);
	    
	    mysqli_query($con,"UPDATE akunn SET passw='$hashpass' WHERE id=1");
	    
	    echo "
            <div class='alert alert-success 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> Ini password baru anda. Catat '$newpass' langsung login. <a href='../login/'>KLIK DISINI</a>. Jangan lupa ganti password anda di menu ubah password dalam member area.
            </div>
            ";
        
	}
	
	else
	    echo "
            <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> PIN anda salah. :(
            </div>
        ";    
	 
    
}
?>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Lupa User Password Login App Auto BiznisTop</title>
     <link rel="shortcut icon" href="../images/abt.png" />
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="page-wrap d-flex flex-row align-items-center">
    <div class="container">
    	<div class="row">
    		<div class="col-md-3">
    		    <img src="https://2.bp.blogspot.com/-AWfFPyMDWH8/XC6fm0SbLVI/AAAAAAAADOQ/Jd7flD_43UgXLaBqEhGRnhedHRFRKPoxwCLcBGAs/s320/auto%2Bbiznistop.png?text=logo" class="img-fluid rounded-circle shadow-sm" alt="" />
    		</div>
    		<div class="col-md-9">
    		    <h2 class="font-weight-light">Lupa Password?</h2>
    		    Masukan PIN Anda.
    		    <form action="" method="POST">
    		        <input class="form-control form-control-lg" name="pass" type="password" placeholder="PIN" required/>
    		        
    		        <div class="text-right my-3">
    		            <button type="submit" class="btn btn-lg btn-success"name="reset" >Reset Password</button>
    		            
                        <a type="submit" class="btn btn-lg btn-success" href="../login/">Login?</a>
          
    		        </div>
    		    </form>
    		</div>
    	</div>
    </div>
</div>
</body>
</html>