我正在使用https://github.com/ChristianRiesen/otp在 Laravel 4.1.23 站点上集成 2 因素身份验证:秘密生成得很好,二维码图像也是如此,Google Authenticator 能够扫描图片。
但是,我的 iPhone 在 Google Authenticator 应用程序中生成的代码无法验证。我遵循了 README.md 中的示例。
在我的控制器中,我有如下代码:
$secret = GoogleAuthenticator::generateRandom();
$url = GoogleAuthenticator::getQrCodeUrl('totp', 'MySite:'.Auth::user()->email, $secret);
// Save the secret with the user's data
if (!Auth::user()->secret) {
Auth::user()->secret = $secret;
Auth::user()->save();
}
return View::make('2fa')->with('secret', $secret)->with('url', $url);
然后在我看来(2fa.blade.php),我有如下代码:
<strong>Secret Key:</strong> {{ $secret }}
<strong>QR Code</strong> <br/>
<img src="{{ $url }}" />
<form action="/confirm_key" method="post">
<label for="key">Enter the generated key:</label>
<input type="text" name="key" id="key"/>
<input type="submit" id="submit" value="Confirm Key"/>
</form>
这一切似乎都在起作用。表单发布到以下控制器函数:
public function postTwoFactorAuthentication() {
// Now how to check
$otp = new Otp();
if ($otp->checkTotp(Base32::decode(Auth::user()->secret), Input::get('key'))) {
return 'Verified!';
}
// Wrong key
else {
return 'Invalid key!'
}
}
这是非常接近 repo 中的用法示例,但密钥(令牌)永远不会验证。我在这里错过了什么吗?Laravel 是不是在搞什么鬼?
任何帮助表示赞赏。