antonioribeiro / google2fa-qrcode

QRCode for Google2FA
MIT License
107 stars 25 forks source link

Inconsistency between QR code and the exact value. #24

Open JamieCee20 opened 11 months ago

JamieCee20 commented 11 months ago

So I create the code as follows:

$secretKey = $this->twofa->generateSecretKey(); // user define key

Then create the QR code

 $twofaQrCode = $this->twofa->getQRCodeUrl($config['qr_company'], $user->email, $secretKey);
        // render qr code url as a scanable image
        $writer = new Writer(
            new ImageRenderer(
                new RendererStyle(400),
                new ImagickImageBackEnd()
            )
        );

        // Write code to a string and store image
        $url = $writer->writeString($twofaQrCode);
        Storage::disk('public')->put('qrcode-' . $user->getKey() . '.png', $url);

This had previously worked fine, but now suddenly, the code Im given from the QR code does not match the actual code (There is a brief time that it does but not correct every other time).

I have came into the Google2FA class, and the findValidOTP function, if I dump out the hash_equals($this->oathTotp($secret, $startingTimestamp), $key) it returns false most of the time, if I dump out the code without the hash_equals function, it shows a completely different code to what the QR code in my authenticator app shows.