Files
Hydro/packages/hydrooj/src/lib/verifyTFA.ts
2023-01-23 17:49:40 +08:00

9 lines
257 B
TypeScript

import notp from 'notp';
import b32 from 'thirty-two';
export function verifyTFA(secret: string, code?: string) {
if (!code || !code.length) return null;
const bin = b32.decode(secret);
return notp.totp.verify(code.replace(/\W+/g, ''), bin);
}