mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-30 06:29:23 +02:00
16 lines
423 B
TypeScript
16 lines
423 B
TypeScript
|
import { decodeHex } from "oslo/encoding";
|
||
|
import { TOTPController } from "oslo/otp";
|
||
|
|
||
|
export async function verifyTotpCode(
|
||
|
code: string,
|
||
|
secret: string,
|
||
|
): Promise<boolean> {
|
||
|
const validOTP = await new TOTPController().verify(code, decodeHex(secret));
|
||
|
|
||
|
if (!validOTP) {
|
||
|
await new Promise((resolve) => setTimeout(resolve, 250)); // delay to prevent brute force attack
|
||
|
}
|
||
|
|
||
|
return validOTP;
|
||
|
}
|