<?php

if(isset($_POST['phoneNumber']) && isset($_POST['pin'])){

    require_once "connection.php";


    $phoneNumber = $_POST['phoneNumber'];
    $pin = $_POST['pin'];
    $firstChar = substr($phoneNumber, 0, 1);

 if($firstChar == '0'){
    $phoneReal = $phoneNumber;   
} else {
    $phoneReal = '0' . $phoneNumber;
}

    $sql = "select * from nasabah where phoneNumber='$phoneReal'";

    $result = $con->query($sql);

    if($result->num_rows > 0){
        while($row = $result->fetch_assoc()) {
            if (password_verify($pin,$row["pin"])){
                echo "success";
            }else{
                echo "failure";
            }
        }
        
    } else{

        echo "failure";
    }
}
?>