antonioribeiro / google2fa

A One Time Password Authentication package, compatible with Google Authenticator.
MIT License
1.83k stars 199 forks source link

Code timing incorrect #193

Open JamieCee20 opened 8 months ago

JamieCee20 commented 8 months ago

I have generated the secret, and in my authenticator both entered the key and used the qr code, both return the same codes.

However, when running the Google2FA::verifyGoogle2FA($result, $code, $timeWindow); method, it always returns false until the code changes between 2-4 times. So why is the code in the verify so delayed to what the authenticator is giving me? This also means after the code keeps changing, older codes still work. My window has been changed varying between 0 and 4, still having the same issue

Fludem commented 6 months ago

Hey,

Have you checked the time on the machine hosting your code?

Can you try again on a different machine?

Can you also manually pass a timestamp to the methods of a fixed time where you know what the correct outcomes are so it doesn't rely on your the hosts time?

JamieCee20 commented 6 months ago

Hey,

Have you checked the time on the machine hosting your code?

Can you try again on a different machine?

Can you also manually pass a timestamp to the methods of a fixed time where you know what the correct outcomes are so it doesn't rely on your the hosts time?

@Fludem Ah I forgot to update the ticket. Yeah, so I found out my machine was 2 minutes out of sync with the current time (Not sure how that ended up happening as it should have been set to automatic) But I correct that and its back working