checkPassword($login, $password, '%%SYSTEM%%')) { return $next($request); } return $this->unauthorized(); } private function checkPassword(string $login, string $password, string $passwordFile): bool { if (! is_readable($passwordFile)) { return false; } $handle = fopen($passwordFile, 'rb'); if ($handle === false) { return false; } try { while (($line = fgets($handle)) !== false) { $parts = explode(':', trim($line), 2); if (count($parts) !== 2 || ! hash_equals($parts[0], $login)) { continue; } $storedHash = trim($parts[1]); return $storedHash !== '' && password_verify($password, $storedHash); } } finally { fclose($handle); } return false; } private function unauthorized(): Response { return response('INVALID USERNAME OR PASSWORD. ACCESS DENIED', 401) ->header('WWW-Authenticate', 'Basic realm="RESTRICTED ACCESS"'); } }