39 lines
975 B
PHP
39 lines
975 B
PHP
<?php
|
|
if((!isset($_POST['username'])) || (!isset($_POST['password']))) {
|
|
header("Location: ./");
|
|
exit();
|
|
}
|
|
|
|
include('config.php');
|
|
$conn = mysqli_connect($host, $user, $pass, $dbnm);
|
|
|
|
session_start();
|
|
|
|
$stmt = $conn->prepare("SELECT * FROM uzytkownicy WHERE username = ?;");
|
|
$stmt->bind_param("s", $_POST["username"]);
|
|
$stmt->execute();
|
|
|
|
$result = $stmt->get_result();
|
|
|
|
if($result->num_rows < 1) {
|
|
header("Location: ./login.php?error=true");
|
|
exit();
|
|
}
|
|
|
|
$cred = $result->fetch_assoc();
|
|
|
|
if(password_verify($_POST['password'], $cred['password_hash'])) {
|
|
$_SESSION['username'] = $cred['username'];
|
|
$_SESSION['user_id'] = $cred['id'];
|
|
$_SESSION['user_rights_level'] = $cred['rights_level'];
|
|
$_SESSION['logged'] = true;
|
|
|
|
header("Location: ./");
|
|
exit();
|
|
} else {
|
|
header("Location: ./login.php?error=true");
|
|
exit();
|
|
}
|
|
|
|
?>
|