120 lines
4.6 KiB
PHP
120 lines
4.6 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/functions.php';
|
|
require_once __DIR__ . '/app/rate-limit.php';
|
|
require_once __DIR__ . '/app/totp.php';
|
|
|
|
$pdo = app_db_pdo();
|
|
$errors = [];
|
|
|
|
// Ohne angefangene Anmeldung hat diese Seite keinen Sinn - und darf auch
|
|
// nichts verraten. Zurueck zum Login.
|
|
$userId = app_totp_challenge_user_id();
|
|
if ($userId === null) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
app_require_csrf();
|
|
|
|
// Sechs Ziffern sind schnell durchprobiert: hier ist das Limit enger als
|
|
// beim Passwort und haengt zusaetzlich am Konto, nicht nur an der IP.
|
|
$userBucketOk = app_rate_limit_check($pdo, '2fa_user:' . $userId, 5, 900);
|
|
$ipBucketOk = app_rate_limit_check($pdo, '2fa_ip:' . app_client_ip(), 20, 900);
|
|
|
|
if (!$userBucketOk || !$ipBucketOk) {
|
|
$errors[] = 'Zu viele Versuche. Bitte warte einige Minuten.';
|
|
} else {
|
|
$code = trim((string)($_POST['code'] ?? ''));
|
|
|
|
// Ein Wiederherstellungscode enthaelt Buchstaben, ein App-Code nie -
|
|
// daran laesst sich beides ohne zusaetzliches Feld unterscheiden.
|
|
$looksLikeRecoveryCode = preg_match('/[a-zA-Z]/', $code) === 1;
|
|
|
|
$accepted = $looksLikeRecoveryCode
|
|
? app_totp_consume_recovery_code($pdo, $userId, $code)
|
|
: app_totp_verify_for_user($pdo, $userId, $code);
|
|
|
|
if ($accepted) {
|
|
app_totp_finish_login($pdo, $userId);
|
|
}
|
|
|
|
$errors[] = 'Der Code stimmt nicht. Bitte prüfe die Uhrzeit deines Geräts und versuche es erneut.';
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
<!DOCTYPE HTML>
|
|
<html lang="de">
|
|
<head>
|
|
<title>Kaffeeliste Bestätigung</title>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<link rel="stylesheet" href="assets/css/main.css" />
|
|
<link rel="stylesheet" href="assets/css/public.css" />
|
|
<?php echo app_analytics_head_html(); ?>
|
|
</head>
|
|
<body class="is-preload public-page">
|
|
<div class="public-shell">
|
|
<section class="public-auth">
|
|
<nav class="public-nav" aria-label="Hauptnavigation">
|
|
<strong><a href="landing.php">Kaffeeliste</a></strong>
|
|
<ul class="actions">
|
|
<li><a href="login.php" class="button">Abbrechen</a></li>
|
|
</ul>
|
|
</nav>
|
|
|
|
<div class="public-auth-grid">
|
|
<div class="public-auth-copy">
|
|
<h1>Bestätigung</h1>
|
|
<p>Dein Konto ist mit einem zweiten Faktor geschützt. Gib den sechsstelligen Code
|
|
aus deiner Authenticator-App ein.</p>
|
|
</div>
|
|
|
|
<div class="public-panel">
|
|
<h2>Zur App</h2>
|
|
|
|
<?php if ($errors !== []): ?>
|
|
<div class="hint-box error">
|
|
<?php foreach ($errors as $error): ?>
|
|
<p><?php echo saas_html($error); ?></p>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="post" action="zwei-faktor.php">
|
|
<?php echo app_csrf_field(); ?>
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<label for="code">Code</label>
|
|
<input type="text" name="code" id="code" inputmode="numeric"
|
|
autocomplete="one-time-code" autofocus required
|
|
placeholder="123456">
|
|
</div>
|
|
</div>
|
|
<ul class="actions">
|
|
<li><button type="submit" class="primary">Bestätigen</button></li>
|
|
</ul>
|
|
</form>
|
|
|
|
<p>Kein Zugriff auf die App? Gib stattdessen einen deiner
|
|
Wiederherstellungscodes ein.</p>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<footer class="public-footer-links">
|
|
<a href="impressum.php">Impressum</a>
|
|
<a href="agb.php">AGB</a>
|
|
<a href="datenschutz.php">Datenschutz</a>
|
|
<a href="avv.php">AVV</a>
|
|
<a href="widerruf.php">Widerrufsbelehrung</a>
|
|
<?php echo app_analytics_footer_settings_button_html(); ?>
|
|
</footer>
|
|
<?php echo app_analytics_body_html(); ?>
|
|
</body>
|
|
</html>
|