<?php 
session_start();
include '../../koneksi/koneksi.php';

$username = $_POST['user'];
$pass     = $_POST['pass'];

// cek user
$result = mysqli_query($conn, "SELECT * FROM admin WHERE username = '$username'");
$row    = mysqli_fetch_assoc($result);

if ($row) {
    $user = $row['username'];
    $ps   = $row['password'];

    if ($username == $user) {
        if (password_verify($pass, $ps)) {
            // session login
            $_SESSION["admin"]  = true;
            $_SESSION["id"]     = $row['id'];
		    $_SESSION["username"] = $row['username'];   
            $_SESSION["level"]  = $row['level'];    

            header('location:../halaman_utama.php');
            exit;
        } else {
            echo "
            <script>
            alert('USERNAME/PASSWORD SALAH');
            window.location = '../index.php';
            </script>
            ";
        }
    }
} else {
    echo "
    <script>
    alert('USERNAME/PASSWORD SALAH');
    window.location = '../index.php';
    </script>
    ";
}
?>
