pragmarx / google2fa-laravel verifyKey始终返回false

问题描述

PHP v7.4,Laravel v7.28.3 我使用pragmarx / google2fa-laravel

QR代码生成

$google2fa = app('pragmarx.google2fa');
$google2fa->setAlgorithm(Constants::SHA512);
$secret = $google2fa->generateSecretKey(64);
$user->google2fa_secret = $secret;
$user->save();

$QR_Image = $google2fa->getQRCodeInline(
    config('app.name'),$user->email,$user->google2fa_secret
);

然后我在前端渲染QR。 Qr代码看起来非常完美,我通过Google 2fa应用程序对其进行了扫描,并且代码生成器已成功添加到该应用程序中。

当我尝试从应用验证代码时,它总是返回false。验证码:

 $code = 'I paste here the code from the application manually';
 $google2fa = app('pragmarx.google2fa');
 var_dump($google2fa->verifyKey($user->google2fa_secret,$code,10));

但是,当我使用$ user-> google2fa_secret(我可以在数据库中对其进行检查)手动将代码生成添加到移动应用程序时,它可以完美运行,该生成器中的所有代码都通过了验证。似乎在生成的QR图像中有问题...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)