dqab0824 2019-03-27 22:53
浏览 97
已采纳

服务器上的时间不匹配 - php中的双因素身份验证

I've created two-factor authentication in PHP using google authenticator. It works well on my localhost, but on my website the generated code was mismatched. I found this is a time configuration issue. assist me to set up time on two-factor.

public function verifyCode($secret, $code, $discrepancy = 1, $currentTimeSlice = null)
{
    if ($currentTimeSlice === null) {
        $currentTimeSlice = floor(time() / 30);
    }

    for ($i = -$discrepancy; $i <= $discrepancy; $i++) {
        $calculatedCode = $this->getCode($secret, $currentTimeSlice + $i);
        if ($calculatedCode == $code ) {
            return true;
        }
    }

    return false;
}
  • 写回答

1条回答 默认 最新

  • duandai0373 2019-03-29 04:35
    关注

    Most likely it is a time drift on the web server. Make sure the time on the web server is correct and precise (UTC).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?