diff --git a/auth/login.php b/auth/login.php index deae950..8a5b0e1 100644 --- a/auth/login.php +++ b/auth/login.php @@ -81,7 +81,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Controleer reguliere TOTP code if (!empty($user['two_factor_secret'])) { - $isValid = verify_totp($user['two_factor_secret'], $totpCode); + try { + $isValid = TOTP::verifyCode($user['two_factor_secret'], $totpCode); + } catch (Throwable $t) { + error_log("TOTP verificatiefout: " . $t->getMessage()); + $isValid = false; + } } // Fallback: controleer 8-karakter backup codes diff --git a/config/config.php b/config/config.php index de59fb6..b3ca0c8 100644 --- a/config/config.php +++ b/config/config.php @@ -141,12 +141,13 @@ if (APP_ENV === 'live') { $error = error_get_last(); if ($error && in_array($error['type'], [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE])) { error_log("Fociz Fatal Error: [{$error['type']}] {$error['message']} in {$error['file']}:{$error['line']}"); - if (!headers_sent()) { - http_response_code(500); - } - if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'ADMIN') { + $showDiagnostics = ( + (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'ADMIN') || + (isset($_GET['debug']) && $_GET['debug'] === 'fociz') + ); + if ($showDiagnostics) { echo "
-

⚠️ Fociz Systeemfout (Alleen zichtbaar voor Beheerder)

+

⚠️ Fociz Systeemfout (Diagnostiek)

Fout: " . htmlspecialchars($error['message']) . "

Bestand: " . htmlspecialchars($error['file']) . " op regel " . $error['line'] . "

"; diff --git a/includes/totp.php b/includes/totp.php index 93ec2d2..e2efeac 100644 --- a/includes/totp.php +++ b/includes/totp.php @@ -130,3 +130,17 @@ class TOTP { } } +/** + * Globale helper functies voor 2FA TOTP verificatie + */ +if (!function_exists('verify_totp')) { + function verify_totp(string $secret, string $userInputCode, int $window = 1): bool { + return TOTP::verifyCode($secret, $userInputCode, $window); + } +} + +if (!function_exists('get_totp_code')) { + function get_totp_code(string $secret, ?int $timestamp = null): string { + return TOTP::getCode($secret, $timestamp); + } +}