<?php
defined("BASEPATH") or exit("No direct access allowed");
error_reporting(0);
if (isset($_POST['ubah'])){

    $options = [
    'cost' => 10,
    ];
    
    $userr = mysqli_real_escape_string($con,$userr);
    $passw1 = mysqli_real_escape_string($con,$passw1);
    $passw2 = mysqli_real_escape_string($con,$passw2);
    //$passw2 = create_hash($passw2);
    $passw2 = password_hash($passw2,PASSWORD_DEFAULT,$options);
    
    $cek=mysqli_fetch_row(mysqli_query($con,"select * from akunn where id=1"));
	$passd=$cek[2];
	    
    //if (validate_password($passw1, $passd)){
    if (password_verify($passw1, $passd)){    
        
        mysqli_query($con,"update akunn set username='$userr', passw='$passw2' where id=1");
    
        echo '
        
        <script>
        	swal("Good Job","Password berhasil diubah","success");
        </script>
        ';
        
    }else{
       echo '
       <script>
        	swal("Good Job","Password lama salah","error");
        </script>
       ';    
    }    
        
}

$data=mysqli_fetch_row(mysqli_query($con,"select * from akunn where id=1"));

?>
   
    
   <div class="card-header">

          <nav aria-label="breadcrumb">
                      <ol class="breadcrumb bg-warning text-white-all">
                        <li class="breadcrumb-item"><a href="#"><i class="fas fa-tachometer-alt"></i> Home</a></li>
                        <li class="breadcrumb-item"><a href="#"><i class="far fa-file"></i> Password</a></li>
                        <li class="breadcrumb-item active" aria-current="page"><i class="fas fa-list"></i> Ubah</li>
                      </ol>
                    </nav>
					
          </div>
          
    <div class="card-body">
     <div class="alert alert-primary alert-has-icon p-4">
            <div class="alert-icon"><i class="far fa-lightbulb"></i></div>
            <div class="alert-body">
            <div class="alert-title">Petunjuk:</div>
            1. Pastikan anda mencatat username dan password.<br>
            2. Jika lupa password, gunakan fitur lupa password. <br>
            3. Pastikan anda mengubah PIN standart 1234 sebelum mengubah password di menu setting.
            </div>
            </div>                  
                   
                <form action="" method="POST"> 
                    
                       
                        <div class="form-group">
                            <label for="tiga" class="col-sm-2 control-label">Username</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="userr" id="tiga" value=""  required>
                                <i>Digunakan untuk login</i>
                            </div>
                        </div>
                        <hr>
                        <div class="form-group">
                            <label for="tiga" class="col-sm-2 control-label">Password Lama</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" name="passw1" id="tiga" value=""  required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="tiga" class="col-sm-2 control-label">Password Baru</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" name="passw2" id="tiga" value=""  required>
                            </div>
                        </div>
                        
                        <div class="form-group">
                          <div class  ="col-sm-4">
                            <button type="submit" class="btn btn-primary" name="ubah"><span class="glyphicon glyphicon-pencil"></span>Ubah Password</button>
                          </div>
                        </div>

                </form>
            </div>
        
      
    