We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can you please help me try to figure out why TOTP tokens generated by other libraries don't match. Here is the code that I am using
const speakeasy = require('speakeasy'); const otpauth = require('otpauth'); const otplib = require('otplib'); const secret = 'this is a secret'; const digits = 6; const period = 30; const algorithm = 'sha1'; // Get the current epoch time in seconds const epoch = Math.floor(Date.now() / 1000); // Generate TOTP using speakeasy const speakeasyToken = speakeasy.totp({ secret, encoding: 'ascii', step: period, digits, algorithm, time: epoch }); console.log(`Speakeasy Token: ${speakeasyToken}`); // Generate TOTP using otpauth const otpauthTOTP = new otpauth.TOTP({ secret: otpauth.Secret.fromUTF8(secret), digits, period, algorithm }); const otpauthToken = otpauthTOTP.generate({ time: epoch }); console.log(`OTPAUTH Token: ${otpauthToken}`); // Generate TOTP using otplib otplib.totp.options = { step: period, digits, algorithm, epoch: epoch * 1000 }; const otplibToken = otplib.totp.generate(secret); //console.log(`OTPLIB Options: ${JSON.stringify(otplib.totp.allOptions())}`); console.log(`OTPLIB Token: ${otplibToken}`);
output:
Speakeasy Token: 006867 OTPAUTH Token: 006867 OTPLIB Token: 395990
I am using epoc to make the test more stable however I tried different approaches but none worked.
Thanks
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Can you please help me try to figure out why TOTP tokens generated by other libraries don't match. Here is the code that I am using
output:
I am using epoc to make the test more stable however I tried different approaches but none worked.
Thanks
The text was updated successfully, but these errors were encountered: