import { createHash, timingSafeEqual } from "crypto";

export function hashPassword(plain: string): string {
  return createHash("sha256").update(plain, "utf8").digest("hex");
}

export function verifyPassword(plain: string, hashed: string): boolean {
  try {
    const a = Buffer.from(hashPassword(plain));
    const b = Buffer.from(hashed);
    return a.length === b.length && timingSafeEqual(a, b);
  } catch {
    return false;
  }
}


