Fix undefined verify_totp function in login.php and add TOTP helper functions; enhance debug diagnostics

This commit is contained in:
2026-09-09 18:03:56 +02:00
parent dfaa8ba7a8
commit 0b9e92eded
3 changed files with 26 additions and 6 deletions
+6 -1
View File
@@ -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
+6 -5
View File
@@ -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 "<div style='font-family: monospace; background: #0c0f17; color: #ef4444; padding: 25px; margin: 20px; border-radius: 12px; border: 1px solid #dc2626;'>
<h3>⚠️ Fociz Systeemfout (Alleen zichtbaar voor Beheerder)</h3>
<h3>⚠️ Fociz Systeemfout (Diagnostiek)</h3>
<p><strong>Fout:</strong> " . htmlspecialchars($error['message']) . "</p>
<p><strong>Bestand:</strong> " . htmlspecialchars($error['file']) . " op regel " . $error['line'] . "</p>
</div>";
+14
View File
@@ -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);
}
}