-
-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
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
Why sometimes is invalid my token? #67
Comments
With a bit debugging I notice that hotpToken() function calculate systemToken wrong (inside hotpCheck function) and when is called otplibUtils.isSameToken(token, systemToken) obviously is different. |
hi @thEpisode I ran the snippet and could reproduce the issue. However it is not a problem with the function. In the above snippet, you're:
In Authenticator and TOTP which are time based, any tokens generated within a 5s time window is the same. As such, if you generate a token at In the snippet above, when you generate a token and wait for Try doing this: // instead of
otplib.authenticator.options = {
step: step
}
// use
otplib.authenticator.options = {
step: step,
window: [1, 0]
}
// instead of
const isValid = otplib.authenticator.check(singleToken, secret)
// use
const isValid = otplib.authenticator.checkDelta(singleToken, secret) You should see some values being returned as Hope that helps :) |
oh yes thanks, I need to read more about this window in this moment is not very clear for me, meanwhile could you guide me to know what is the right way to generate an OTP every 5 seconds? |
The following is a sample terminal application. const otplib = require('otplib');
const ora = require('ora');
let step = 5;
let currToken = 'Generating...';
otplib.authenticator.options = {
step: step
};
const spinner = ora(currToken).start();
const secret = otplib.authenticator.utils.encodeKey('your own private key');
function generator() {
const epoch = Math.floor(new Date().getTime() / 1000);
const count = epoch % step;
if (count === 0) {
currToken = otplib.authenticator.generate(secret);
}
spinner.text = `[${step - count}s] - ${currToken}`;
}
setInterval(generator, 1000); |
Woah, wonderful, thanks |
Hey! Just wanted to ask about what does the |
Hi, this is an strange behavior because sometimes is invalid the code without any modification. I used check() and verify() functions for it.
How to reproduce:
Details:
The text was updated successfully, but these errors were encountered: