v2.4.6: TOTP allow multiple codes, composer update, PHPStan

This commit is contained in:
2026-01-28 14:09:10 +01:00
parent 4bcfc3ad9f
commit e82e6ee6a7
5 changed files with 326 additions and 291 deletions

View File

@@ -10,6 +10,7 @@
"geoip2/geoip2": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6"
"phpunit/phpunit": "^9.6",
"phpstan/phpstan": "^2.1"
}
}

586
Core/External/composer.lock generated vendored
View File

File diff suppressed because it is too large Load Diff

11
Core/External/phpstan.neon vendored Normal file
View File

@@ -0,0 +1,11 @@
parameters:
level: 6
paths:
- ../../
excludePaths:
- ./vendor/*
- ../../test/*
- ../../Core/Cache/*
- ../../Site/Cache/*

View File

@@ -58,8 +58,19 @@ class TimeBasedTwoFactorToken extends TwoFactorToken {
return substr(str_pad(strval($code), $length, "0", STR_PAD_LEFT), -1 * $length);
}
public function verify(string $code): bool {
return $this->generate() === $code;
public function verify(string $code, int $numCodes = 2): bool {
$now = time();
$length = 6;
$period = 30;
// verify the last $numCodes codes
for ($i = 0; $i < max(1, $numCodes); $i++) {
if ($this->generate($now - $period * i, $length, $period) === $code) {
return true;
}
}
return false;
}
public function getData(): string {

View File

@@ -10,7 +10,7 @@ if (is_file($autoLoad)) {
require_once $autoLoad;
}
const WEBBASE_VERSION = "2.4.5";
const WEBBASE_VERSION = "2.4.6";
spl_autoload_extensions(".php");
spl_autoload_register(function ($class) {