Skip to content
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

OTP code till valid after 30 secondes ! #246

Open
Akrachli opened this issue Dec 27, 2024 · 3 comments
Open

OTP code till valid after 30 secondes ! #246

Akrachli opened this issue Dec 27, 2024 · 3 comments

Comments

@Akrachli
Copy link

Hello,
We're using the GoogleAuthenticator Library version 3.2.0, and we're currently experiencing an issue. The OTP code should be valid for only 30 seconds, but I've noticed that even after 30 seconds, it can still be used for a much longer period, usually around 3 to 4 minutes. Additionally, when the OTP code is used, I logged out, logged back in, and used the same OTP code, and it still worked!

I made sure that the timezone is properly configured and that synchronization with the NTP server is working, but I'm still facing the same issue!

@ahwm
Copy link
Collaborator

ahwm commented Dec 27, 2024

Checking whether a code has been used is outside the scope of this library since that requires specific logic in the application. The library is stateless and does not have context of the user that's being validated. It's just checking if a given code with a certain private key is valid for the time period.

The default validity period is 5 minutes (to allow for clock drift), but that can be adjusted by using an overload:

var tfa = new TwoFactorAuthenticator();
var isValid = tfa.ValidateTwoFactorPIN(secretKey, codeFromClient, Timespan.FromMinutes(1));

@Akrachli
Copy link
Author

Hello,

We have adjusted the clock drift, and it works well. However, we encountered another problem. When we set the code for 30 seconds, an additional tolerance of 30 seconds is added, causing the code to expire after 1 minute instead of the intended duration.

Could you suggest any changes we need to make so that the app accepts exactly 30 seconds without a +30 seconds tolerance?

Thank you so much! I appreciate your help.

@Akrachli Akrachli reopened this Jan 21, 2025
@ahwm
Copy link
Collaborator

ahwm commented Jan 21, 2025

I did some testing and it looks like using a time tolerance of 0 seconds will get you what you are looking for. The "current" will always be validated for the length of time specified in the constructor (30 seconds is used if not specified).

new TwoFactorAuthenticator(HashType.SHA256)
    .GetCurrentPINs(this.txtSecretKey.Text, TimeSpan.FromSeconds(0))

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants