initial commit
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
20
src/utils/totp.ts
Normal file
20
src/utils/totp.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import * as OTPAuthLib from 'otpauth';
|
||||
import { decrypt } from './encryption';
|
||||
|
||||
export const OTPAuth = {
|
||||
verify(encryptedSecret: string, code: string): boolean {
|
||||
try {
|
||||
const secret = decrypt(encryptedSecret);
|
||||
const totp = new OTPAuthLib.TOTP({
|
||||
secret: OTPAuthLib.Secret.fromBase32(secret),
|
||||
algorithm: 'SHA1',
|
||||
digits: 6,
|
||||
period: 30,
|
||||
});
|
||||
const delta = totp.validate({ token: code, window: 1 });
|
||||
return delta !== null;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user