PHPGangsta / GoogleAuthenticator

PHP class to generate and verify Google Authenticator 2-factor authentication

Home Page:http://phpgangsta.de/4376

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not verify the code generated by Google Authenticator app after deploying the code on the server

ashish-devclever opened this issue · comments

Hi,

I have used this library to enable the 2FA in our app. It is working absolutely working fine on my local environment but when we deployed the code on staging it is not able to validate the verification code generated by Google Authenticator app.
Both the environments are using Php 7.3. and according to the the issue #61, the mbstring.func_overload value is already set to 0. The only deference I can see the default timezone. On server it is Europe/London where as in local it is UTC. I have also changed in my local system to Europe/London even it is working fine. Attached is the configuration in php.ini of server for your reference.

Screen Shot 2021-11-01 at 10 50 07 PM

I have also made the suggested changes in getCode function as mentioned in the #61.

// last arg: When set to TRUE, outputs raw binary data. FALSE outputs lowercase hexits.
// hex string would be more stable in PHP I guess.
$hm = hash_hmac('SHA1', $time, $secretkey, false);

// last nibble is the last hex symbol now. Just turn it to decimal.
$offset = hexdec(substr($hm, -1));

// as each byte is 2 hex symbols, multiply 'substr' args by 2
// turn resulting hex into binary for compliance with further code
$hashpart = hex2bin(substr($hm, $offset * 2, 8));

But still no luck. It would be a great help if anyone can help on this to resolve.

Thanks and Regards
Ashish