Login

$debug[] = "MongoDB Passwort-Hash Info: " . htmlspecialchars(json_encode(password_get_info($dbPassword))) . ""; } // Zeige, wie ein Hash für das eingegebene Passwort aussehen würde $hashTest = debug_password_hash($password); $debug[] = "Neuer Hash für eingegebenes Passwort (zum Vergleich): " . htmlspecialchars($hashTest['hash']) . ""; $debug[] = "Hash-Info für neuen Hash: " . htmlspecialchars(json_encode($hashTest['info'])) . ""; $is_string = is_string($dbPassword); $strlen = strlen($dbPassword); $verify = ($is_string && $strlen > 0) ? password_verify($password, $dbPassword) : false; $debug[] = "is_string(\$dbPassword): " . ($is_string ? 'true' : 'false') . ""; $debug[] = "strlen(\$dbPassword): " . $strlen . ""; $debug[] = "password_verify(\$password, \$dbPassword): " . htmlspecialchars(var_export($verify, true)) . ""; $debug[] = "password_verify Ergebnis: " . ($verify ? "TRUE" : "FALSE") . ""; // Zeige auch explizit, ob der Hash mit $2y$ beginnt und 60 Zeichen lang ist $debug[] = "Hash beginnt mit: " . htmlspecialchars(substr($dbPassword, 0, 4)) . ""; $debug[] = "Hash-Länge: " . strlen($dbPassword) . ""; if ($user && $is_string && $strlen > 0 && $verify) { $debug[] = "Login erfolgreich mit MongoDB!"; // Regenerate session id so that the new session cookie takes the extended lifetime session_regenerate_id(true); $_SESSION['user'] = [ 'username' => $user['username'], 'roles' => $user['roles'] ?? [], 'email' => $user['email'] ?? '', ]; // Set session cookie lifetime if "remember me" is checked if (!empty($_POST['remember_me'])) { $lifetime = 60*60*24*30; // 30 days setcookie(session_name(), session_id(), [ 'expires' => time() + $lifetime, 'path' => '/', 'secure' => isset($_SERVER['HTTPS']), 'httponly' => true, 'samesite' => 'Lax', ]); } header('Location: /'); exit; } else { $debug[] = "MongoDB Login fehlgeschlagen."; } } catch (\Throwable $e) { $debug[] = "MongoDB Fehler: " . htmlspecialchars($e->getMessage()); $debug[] = "
" . htmlspecialchars($e->getTraceAsString()) . "
"; } $error = "Login fehlgeschlagen!"; } } // Backend: TOTP-Überprüfung if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'verify_totp' && !empty($_SESSION['pending_2fa_user'])) { require_once __DIR__ . '/../vendor/autoload.php'; $username = $_SESSION['pending_2fa_user']; $totp_code = $_POST['totp_code'] ?? ''; $query = new MongoDB\Driver\Query(['username' => $username]); $user = null; foreach ($client->executeQuery($collection, $query) as $doc) { $user = (array)$doc; } if ($user && !empty($user['totp_secret'])) { $totp = new \robthree\TwoFactorAuth\TwoFactorAuth('VG Otterbach-Otterberg'); if ($totp->verifyCode($user['totp_secret'], $totp_code)) { // Login erfolgreich $_SESSION['user'] = $user; unset($_SESSION['pending_2fa_user']); header('Location: /'); exit; } else { $error = 'Ungültiger 2FA-Code!'; } } else { $error = '2FA nicht eingerichtet.'; } } ?> Login VG Otterbach-Otterberg Portal

Login

© 2026 Ihr Unternehmen