PHPGangsta / GoogleAuthenticator

PHP class to generate and verify Google Authenticator 2-factor authentication
http://phpgangsta.de/4376
BSD 2-Clause "Simplified" License
2.26k stars 697 forks source link

verifyCode is returning false sometimes #66

Open anilthedev opened 5 years ago

anilthedev commented 5 years ago

Hi there,

We are using this library in our application from the past few years but recently we are facing issue in enabling the 2 step authentication in our application.

While debugging we found that the verfiyCode function returning false. We are calling the function with the following parameters: $discrepancy = 1 $currentTimeSlice = null and the secret and code.

Please suggest us

Thanks

PHPGangsta commented 5 years ago

As always: Check the time on the server and on your device. They have to be in sync. $discrepancy=1 means: 1 code before the current one, and the next code will be allowed.

I guess your device is 30-60 seconds away from the server, that's why sometimes the code is invalid.

Sync the time of the device to the server, or increase $discrepancy to allow more codes.

anilthedev commented 5 years ago

Hi Thanks for the update. I have checked the $discrepancy value to 3 and checked both the server time and my mobile time both are in sync. Can you please let me know is there any other dependencies.

Thanks

RandianHero commented 5 years ago

This issue happens to us also. It seems some 30 second intervals it works and returns true, others it will always return false, even if the code is correct. We have synced clocks and it didn't help.

kimATwork commented 5 years ago

I had a similar problem. Check out keykrusshas Workaround in https://github.com/PHPGangsta/GoogleAuthenticator/issues/61#issuecomment-482079577. It solved it for me. (Setting mbstring.func_overload to 0 did not).