Finish login

This commit is contained in:
marc-go
2026-02-17 10:01:52 +01:00
parent e2a525964d
commit c82f80fe74
6 changed files with 78 additions and 14 deletions

View File

@@ -29,7 +29,6 @@ class mcServ {
public function checkLogin() {
if (!isset($_COOKIE["session_id"]) || !isset($_COOKIE["device_id"])) {
echo "Keine Cookies gesetzt";
return false;
}
@@ -38,20 +37,27 @@ class mcServ {
$json = json_decode(file_get_contents($config["PATH"] . "/tmp/user_sessions/" . $_COOKIE["username"] . ".json"), true);
if (!isset($json[$_COOKIE["device_id"]])) {
echo "Device ID gibt es nicht im JSON";
return false;
}
$device = json_decode($json[$_COOKIE["device_id"]], true);
if ($device["session_id"] !== $_COOKIE["session_id"]) {
echo "Session IDs stimmen nicht überein";
return false;
}
return true;
}
public function getDB() {
$config = $this->getConf();
$db = new PDO("sqlite:" . $config["DB_PATH"]);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $db;
}
public function generateSessionID() {
$num = rand(1, 999999);
$hash = hash("sha256", $num);