ip geolocation + ping analysis

This commit is contained in:
NextJS
2026-06-02 10:24:58 +00:00
parent dc8377177a
commit 4ed4a10eae
21 changed files with 1141 additions and 168 deletions
+30
View File
@@ -0,0 +1,30 @@
import { timingSafeEqual } from "node:crypto";
function safeEqual(a: string, b: string): boolean {
const aBuf = Buffer.from(a);
const bBuf = Buffer.from(b);
if (aBuf.length !== bBuf.length) return false;
return timingSafeEqual(aBuf, bBuf);
}
export function getAdminUsername(): string {
return process.env.ADMIN_USERNAME?.trim() || "admin";
}
export function getAdminPassword(): string | null {
const password = process.env.ADMIN_PASSWORD?.trim();
return password || null;
}
export function verifyAdminCredentials(
username: string,
password: string,
): boolean {
const expectedUsername = getAdminUsername();
const expectedPassword = getAdminPassword();
if (!expectedPassword) return false;
return (
safeEqual(username, expectedUsername) &&
safeEqual(password, expectedPassword)
);
}