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

totp expire time #80

Open
UfkumDeniz opened this issue May 10, 2024 · 1 comment
Open

totp expire time #80

UfkumDeniz opened this issue May 10, 2024 · 1 comment

Comments

@UfkumDeniz
Copy link

Hi,

First of all "eline sağlık" I can easily read and understand your code.

I need a OTP with expire time 180 seconds. At first, I thought that totp is about expiration duration but as I test, I saw that it is not the case.

Do you know how to overcome this situation?

To test expiration I used following code block. First, I tried 30 seconds and results were unstable.

try {
  String code = totpGenerator.now();
  System.out.println("Generated code: " + code);
  for (int i = 0; i <= 6; i++) {
    boolean verify = totpGenerator.verify(code); // true
    System.out.println(LocalDateTime.now() + " " + (10000 * i) / 1000 + "sec. otp result is: " + verify);

    Thread.sleep(10000);
  }

Generated code: 480366
2024-05-10T11:41:39.821 0sec. otp result is: true
2024-05-10T11:41:49.831 10sec. otp result is: true
2024-05-10T11:41:59.836 20sec. otp result is: true
2024-05-10T11:42:09.852 30sec. otp result is: false
2024-05-10T11:42:19.857 40sec. otp result is: false

Generated code: 915372
2024-05-10T11:42:57.518 0sec. otp result is: true
2024-05-10T11:43:07.529 10sec. otp result is: false
2024-05-10T11:43:17.541 20sec. otp result is: false
2024-05-10T11:43:27.548 30sec. otp result is: false
2024-05-10T11:43:37.557 40sec. otp result is: false

@BastiaanJansen
Copy link
Owner

BastiaanJansen commented May 10, 2024

Hi, thanks for you kind words!

It is correct that the expiration duration does not exactly match your expectation, because the token belongs to a specific time step. You could generate a token with a custom Clock object you control. However I don't think your use case is supported based on RFC6238.

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