動いている

This commit is contained in:
2025-12-07 21:11:48 +09:00
parent e18de43d21
commit 229cc48cb5
4 changed files with 38 additions and 7 deletions

View File

@@ -85,7 +85,7 @@ class Auth {
$token = bin2hex(random_bytes(64));
$expire = time() + $this->tokenDuration;
$newToken = [
'token' => password_hash($token, $algo),
'token' => $token,
'ip' => $ip,
'createDate' => time(),
'expDate' => $expire,
@@ -151,7 +151,7 @@ class Auth {
return \Result::success();
}
public function isUserExist(?string $username): \Result {
public function isUserExist(?string $username = null): \Result {
if (null === $username) return \Result::Error('エラー:ユーザー名をご入力下さい。');
$userList = scandir($this->dataDir);
@@ -167,7 +167,7 @@ class Auth {
////////////////////
private function purgeOldTokens(\stdClass $userData): \stdClass {
private function purgeOldTokens(\stdClass $userData): \stdClass|\Result {
// 有効期限切れたトークンの削除
$out = $userData;
$out->tokens = array_filter($userData->tokens, function($t): bool {
@@ -196,8 +196,12 @@ class Auth {
$path = "{$this->dataDir}{$f}";
if (!is_file($path)) continue;
$content = file_get_contents($path);
if (str_contains($content, $token)) {
if ($token && str_contains($content, $token)) {
$matches[] = $path;
break;
} else if (!$token && str_contains($content, '"username": "'.$username.'",')) {
$matches[] = $path;
break;
}
}
$id = (int)preg_replace('/^(.*?)\.(.*?)$/', "$1", str_replace($this->dataDir, '', $matches[0]));
@@ -277,4 +281,4 @@ class Auth {
return \Result::Success();
}
};
};