mirror of
https://github.com/antonioribeiro/google2fa.git
synced 2026-04-26 00:25:52 +03:00
[GH-ISSUE #163] verifyKeyNewer() not working as expected #307
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/google2fa#307
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @john-nyxcoder on GitHub (Dec 17, 2020).
Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/163
I'm using the following code:
To set the timestamp itself I used the following code (just for testing
verifyKeyNewer()):After setting the timestamp, I tried to enter a current TOTP code to the validate function above.
The timeframe is set to
1as the login function too:It says
validall the time, when usingverifyKeyNewer()any idea where things go wrong?I want to use this library, not the laravel package / bridge.
@john-nyxcoder commented on GitHub (Dec 18, 2020):
@jhoff maybe this is related to your problem too, isn't it?
See: https://github.com/antonioribeiro/google2fa/issues/158
@zortje commented on GitHub (Jan 25, 2021):
The $timestamp variable is actually the timestamp divided with the key regeneration, so you would need to use the following code.
@rubensrocha commented on GitHub (Jul 14, 2021):
My Solution(Laravel 8).
User Model Field: two_factor_time (timestamp default null)
2Fa Middleware:
2Fa Controller (show view):
2Fa Controller (send/validate token):
I used a timestamp in the session and in the database to validate tokens already used before, because when logging out the session is destroyed, preventing the validation of tokens already used.
This way, if the DB field or the session field is null (or both), the middleware redirects the user to the 2FA page. The DB and session timestamp field must be defined for the user to access the secure area.
@imran0 commented on GitHub (Dec 29, 2021):
@zortje @rubensrocha I have tried dividing the unix timestamp by 30 as described in your post but the package still claims the code is incorrect. It simply doesn't accept any OTP's, both new or old.
I have verified the old timestamp value is accurate (and there are no timezone issues), could you advise how you got this working as I am not having much luck.
@Isild commented on GitHub (Jan 27, 2022):
@imran0 there is that what @rubensrocha and @zortje said.
You must divide timestamp by 30. But if you change key regeneration you must use another number.
Best way to get actual number is use this:
And next when you use
it should works.
I don't know how looks yours timestamps format but I use
Carbon::now()->timestampwhich give me seconds since the Unix Epoch(1643290902) and it works.