<?php
require("../config/koneksi.php");
require("../config/function.php");
require("../config/apk.php");

$username = mysqli_escape_string($koneksi, $_POST['username']);
$password = mysqli_escape_string($koneksi, $_POST['password']);
$query = mysqli_query($koneksi, "SELECT * FROM users WHERE username='$username'");
$cek = mysqli_num_rows($query);
$user = mysqli_fetch_array($query);
if ($cek <> 0) {
    if ($user['level'] == 'admin') {
        if (!password_verify($password, $user['password'])) {
            echo "nopass";
        } else {
            $_SESSION['id_user'] = $user['id_user'];
            $_SESSION['level'] = 'admin';
            echo "ok";
			
        }
 } elseif ($user['level'] == 'guru') {

        if ($password == $user['password']) {
            $_SESSION['id_user'] = $user['id_user'];
            $_SESSION['level'] = 'guru';
            echo "ok";
		
		} else {
            echo "nopass";
        }
	 }
} elseif ($cek == 0) {
    echo "td";
}