【发布时间】:2014-12-19 19:16:58
【问题描述】:
我已经使用https://github.com/chregu/GoogleAuthenticator.php 为我正在开发的 Web 应用程序构建了 2 因素身份验证。一切都可以产生秘密,甚至代码也可以工作。 现在我在不同的服务器中设置了相同的代码并生成了新的密钥并将其添加到谷歌身份验证器移动应用程序中,现在移动中生成的代码不匹配。
我通过比较两台服务器上的结果进行挖掘并注意到 time() 函数返回不同的时间(1 小时差异)然后我强制我的第二台服务器(谷歌代码不起作用)与第一台服务器具有相同的时间并且它工作.所以我真的很困惑这是某种时区问题吗?因为我真的需要这些服务器有自己的时区。
有什么解决办法吗?
我也关注了https://support.google.com/accounts/answer/185834?hl=en 并同步了我的谷歌身份验证器应用程序仍然无法正常工作。一小时后,移动应用程序中生成的代码可以在我的第二台服务器上运行。任何人都可以帮助我或建议我一种不同的方法。
这是我用来连接上述库的代码
class googleAuthLibrary extends GoogleAuthenticator
{
public function getSecretKey()
{
$secretKey = $this->generateSecret();
return $secretKey;
}
public function getQRLink($username, $hostname, $secretKey)
{
$url = 'https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=';
$qrCode = 'otpauth://totp/'.$username.'@'.$hostname.'?secret='.$secretKey;
$url = $url.$qrCode;
return $url;
}
public function getAuthCode($secretKey)
{
$authCode =$this->getCode($secretKey);
return $authCode;
}
}
【问题讨论】:
-
经过深思熟虑 :) 我正在考虑保存更多信息,例如用户时区,然后通过根据他们所属的时区操纵时间来获取代码。还有其他更好的解决方案吗?
标签: php authentication google-authentication google-authenticator