<?php 
    ob_start();
    session_start(); 
?>

<?php
    $user = $_POST['uname'];
    $pass = $_POST['psw'];

    if ($user=="zkr") {
        if(crypt($pass, '$1$ItcURmiP$jdUr1qLvk.81b40Q/BYFh0') == '$1$ItcURmiP$jdUr1qLvk.81b40Q/BYFh0') {
            $_SESSION['login_ok']="1";
            header("Location:/");
        }
    }

    class MyDB extends SQLite3 {
        function __construct() {
           $this->open('/kirac/db/misc.db');
           $this->enableExceptions(true);
        }
     }
  
     $db = new MyDB();
     if(!$db) {
        header("Location:/");
     }

     $sql =<<<EOF
        SELECT * from tblusers;
EOF;
     try {
        $ret = $db->query($sql);
        while($row = $ret->fetchArray(SQLITE3_ASSOC) ) {
            if ($user==$row['user']) {
                if(crypt($pass, $row['pass']) == $row['pass']) {
                    $_SESSION['login_ok']="1";
                    break;
                }
            }
        }            
     } catch (Exception $e) {
        //echo $e->getMessage();
     }
     $db->close();

    header("Location:/");
?>
