mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 17:46:28 +08:00
core: migrate notp to otpauth (#1157)
This commit is contained in:
1 parent
bbcaa61d64
commit
62cabb1034
2 files changed
+5
-8
No files matched your search
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user