[GH-ISSUE #47] problem with KEY_REGENERATION #21

Closed
opened 2026-02-25 20:32:12 +03:00 by kerem · 12 comments
Owner

Originally created by @parnus01 on GitHub (Aug 24, 2016).
Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/47

i change value from 30second such as 25,45 to reduce lifetime of generate code but it not work

help me please i am newbie for google2FA

Originally created by @parnus01 on GitHub (Aug 24, 2016). Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/47 i change value from 30second such as 25,45 to reduce lifetime of generate code but it not work help me please i am newbie for google2FA
kerem closed this issue 2026-02-25 20:32:12 +03:00
Author
Owner

@aik099 commented on GitHub (Aug 24, 2016):

It did work, but we're checking 2 codes before and 2 codes after matching one to compensate for network delay between user submitting the form and time, when it reaches the server.

<!-- gh-comment-id:241972497 --> @aik099 commented on GitHub (Aug 24, 2016): It did work, but we're checking 2 codes before and 2 codes after matching one to compensate for network delay between user submitting the form and time, when it reaches the server.
Author
Owner

@parnus01 commented on GitHub (Aug 24, 2016):

ok but i have another question , when is verify code and it valid,after that i use same code and it can verify too how can i customize for one verify for one code

<!-- gh-comment-id:242001212 --> @parnus01 commented on GitHub (Aug 24, 2016): ok but i have another question , when is verify code and it valid,after that i use same code and it can verify too how can i customize for one verify for one code
Author
Owner

@aik099 commented on GitHub (Aug 24, 2016):

Same code can be used any number of times, until it's expired (30 seconds by default). This is how algorithm (not specific to this library) works (time-based code generation).

You can configure window size (number of codes before/after this one are checked) via $window parameter, when calling verifyKey method (see https://github.com/antonioribeiro/google2fa/blob/master/src/Google2FA.php#L212) as well.

<!-- gh-comment-id:242001900 --> @aik099 commented on GitHub (Aug 24, 2016): Same code can be used any number of times, until it's expired (30 seconds by default). This is how algorithm (not specific to this library) works (time-based code generation). You can configure window size (number of codes before/after this one are checked) via `$window` parameter, when calling `verifyKey` method (see https://github.com/antonioribeiro/google2fa/blob/master/src/Google2FA.php#L212) as well.
Author
Owner

@parnus01 commented on GitHub (Aug 24, 2016):

until it's expired (30 seconds by default) why after that i can used i timer around 2 minute

but KEY_REGENERATION = 30 in my code

<!-- gh-comment-id:242003594 --> @parnus01 commented on GitHub (Aug 24, 2016): until it's expired (30 seconds by default) why after that i can used i timer around 2 minute but KEY_REGENERATION = 30 in my code
Author
Owner

@aik099 commented on GitHub (Aug 24, 2016):

The problem you describe does happen on demo page https://antoniocarlosribeiro.com/technology/google2fa as well?

<!-- gh-comment-id:242003920 --> @aik099 commented on GitHub (Aug 24, 2016): The problem you describe does happen on demo page https://antoniocarlosribeiro.com/technology/google2fa as well?
Author
Owner

@parnus01 commented on GitHub (Aug 24, 2016):

yes you can try after 30 minute it can used

<!-- gh-comment-id:242004031 --> @parnus01 commented on GitHub (Aug 24, 2016): yes you can try after 30 minute it can used
Author
Owner

@parnus01 commented on GitHub (Aug 24, 2016):

and i dont know if i channge $window What will be change ?

<!-- gh-comment-id:242005217 --> @parnus01 commented on GitHub (Aug 24, 2016): and i dont know if i channge $window What will be change ?
Author
Owner

@aik099 commented on GitHub (Aug 24, 2016):

yes you can try after 30 minute it can used

If generated code is valid past it's expiration time, then it's surely a bug.

and i dont know if i channge $window What will be change ?

Then your code won't be considered valid if all of these criteria are met:

  • your code is valid for 30 seconds
  • you submit code on 29th second of code validity
  • http request reaches web server only after 2 seconds

I think window of 1 is enough to compensate for this. That would allow code to be valid for 3x it's expiration.

<!-- gh-comment-id:242005834 --> @aik099 commented on GitHub (Aug 24, 2016): > yes you can try after 30 minute it can used If generated code is valid past it's expiration time, then it's surely a bug. > and i dont know if i channge $window What will be change ? Then your code won't be considered valid if all of these criteria are met: - your code is valid for 30 seconds - you submit code on 29th second of code validity - http request reaches web server only after 2 seconds I think window of `1` is enough to compensate for this. That would allow code to be valid for 3x it's expiration.
Author
Owner

@parnus01 commented on GitHub (Aug 24, 2016):

very confuse after i change KEY_REGENERATION to 45 60 seconds it can't verify although code just generate

<!-- gh-comment-id:242007099 --> @parnus01 commented on GitHub (Aug 24, 2016): very confuse after i change KEY_REGENERATION to 45 60 seconds it can't verify although code just generate
Author
Owner

@sokai commented on GitHub (Aug 24, 2016):

#23 "[Q] keyRegeneration period and window (key)" was the same intention …

<!-- gh-comment-id:242043080 --> @sokai commented on GitHub (Aug 24, 2016): #23 "[Q] keyRegeneration period and window (key)" was the same intention …
Author
Owner

@parnus01 commented on GitHub (Aug 25, 2016):

i can't change keyRegeneration by 30 right ?

<!-- gh-comment-id:242271272 --> @parnus01 commented on GitHub (Aug 25, 2016): i can't change keyRegeneration by 30 right ?
Author
Owner

@antonioribeiro commented on GitHub (Jun 17, 2017):

Unless you can control the lifetime of your keys in the app your users will use to check the keys (Google Authenticator?), you should never touch key regeneration, those 30 seconds of lifetime for a key are used worldwide.

If you need the password to be available for a little more time, you have to play with window.

I have built a new playground page to help you with this: https://pragmarx.com/google2fa

<!-- gh-comment-id:309193157 --> @antonioribeiro commented on GitHub (Jun 17, 2017): Unless you can control the lifetime of your keys in the app your users will use to check the keys (Google Authenticator?), you should never touch key regeneration, those 30 seconds of lifetime for a key are used worldwide. If you need the password to be available for a little more time, you have to play with `window`. I have built a new playground page to help you with this: https://pragmarx.com/google2fa
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/google2fa#21
No description provided.