<?php
  session_start();
 

if(time() > (($_POST['timestamp'])+30)){
header("location: ../login.php?feedback=Vypršela platnost přihlašovacího formuláře");
exit();
}

if(!empty($_POST['username'])&&!empty($_POST['usurname']))
{
  require_once("../core/dbase.php");
	$username = ($_POST['username']);
	$usurname = ($_POST['usurname']);
	$password = ($_POST['password']);
	
 	$query = "SELECT Jmeno, Prijmeni, Heslo, Opravneni, Skupina FROM lide WHERE `Jmeno`='$username' AND `Prijmeni`='$usurname'";
	$result = $database->query($query);
	
	
		
		$row = $result->fetchArray();
			$db_username = $row['Prijmeni'];
			$db_password = $row['Heslo'];
		 	
		$db_password = hash_hmac('sha1', $_POST['timestamp'],$db_password);
   
		if($_POST['passhash']==$db_password)
		{
			session_start();
			$_SESSION['username']=$row['Jmeno']." ".$db_username;
			$_SESSION['rights']=$row['Opravneni'];
			$_SESSION['group']=$row['Skupina'];
			header("location: ../");
		}
		else
		{
			header("location: ../login.php?feedback=Špatné jméno, nebo heslo");
		}
}
else
{
	header("location: ../login.php?feedback=Je nutno vyplnit všechna pole");
}

?>