login works, but talking via tokens not ready
This commit is contained in:
@@ -16,22 +16,23 @@ class TokenHandler
|
||||
}
|
||||
public static function doesUserHaveToken(string $username): bool
|
||||
{
|
||||
return array_any(self::$tokens, fn($token) => $token['username'] === $username);
|
||||
return array_any(self::$tokens, fn($token) => $token[0] === $username);
|
||||
}
|
||||
public static function getNewTokenForUser(string $username): string
|
||||
{
|
||||
$tokenBody = self::random32Characters() . str_pad(self::$iterations, 5, '0');
|
||||
$tokenBody = self::random32Characters() . str_pad(self::$iterations++, 5, '0');
|
||||
if (self::$iterations >= 99999) {
|
||||
self::$iterations = 0;
|
||||
}
|
||||
self::$tokens[] = [$username, (microtime(true) * 1000), $tokenBody];
|
||||
return self::$tokens[][0] . $tokenBody;
|
||||
$timestamp = microtime(true) * 10000;
|
||||
self::$tokens[] = [$username, $timestamp, $tokenBody];
|
||||
return $timestamp . $tokenBody;
|
||||
}
|
||||
public static function getTokenOwnership(string $controlledToken): string | null
|
||||
{
|
||||
for ($i = 0; $i < count(self::$tokens); ++$i) {
|
||||
$token = self::$tokens[$i];
|
||||
if ($token[0] === $controlledToken[1] . $controlledToken[2]) {
|
||||
if ($token[1] . $token[2] === $controlledToken) {
|
||||
return $token[0];
|
||||
}
|
||||
}
|
||||
@@ -42,12 +43,12 @@ class TokenHandler
|
||||
for ($i = 0; $i < count(self::$tokens); ++$i) {
|
||||
$token = self::$tokens[$i];
|
||||
// 1 hour
|
||||
if (time() - ($token[0] / 1000) > 3600) {
|
||||
if (time() - ($token[1] / 10000) > 3600) {
|
||||
array_splice(self::$tokens, $i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function deleteTokensForUser(string $user)
|
||||
public static function deleteTokensForUser(string $user): void
|
||||
{
|
||||
for ($i = 0; $i < count(self::$tokens); ++$i) {
|
||||
if (self::$tokens[$i][0] === $user) {
|
||||
|
||||
Reference in New Issue
Block a user