core: migrate notp to otpauth (#1157)

This commit is contained in:
Baoshuo authored and GitHub committed 2026-05-09 21:04:55 +08:00
1 parent bbcaa61d64
commit 62cabb1034
2 files changed
+5 -8

No files matched your search

+4 -5
View File
@@ -1,8 +1,7 @@
import notp from 'notp';
import b32 from 'thirty-two';
import { Secret, TOTP } from 'otpauth';
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);
if (!code || !code.length) return false;
const totp = new TOTP({ secret: Secret.fromBase32(secret), algorithm: 'SHA1', digits: 6, period: 30 });
return totp.validate({ token: code.replace(/\W+/g, '') }) !== null;
}