ip geolocation + ping analysis
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user