如何正确实施Google身份验证器

时间:2018-04-19 19:44:48

标签: php authentication google-authenticator

如何正确实施Google身份验证器

我正试图围绕Google身份验证器实施。我希望能够复制iPhone谷歌身份验证器应用程序,换句话说,我希望我自己的应用程序吐出我的Gmail验证码,就像我的iPhone应用程序一样。我尝试了这个库,我无法使它工作,或者可能有一些我做错了。 https://github.com/PHPGangsta/GoogleAuthenticator

以下是我采取的步骤:

1 - Went to accounts.google.com and scanned my barcode using my iPhone
2 - Saved the secret key
3 - And using the PHPGangsta library, generate 6 digit code with secret key 
4 - Use code to sign in to my google account
5 - Sign in Failed 
6 - Me sad

这是我的代码:

<?php
require_once 'GoogleAuthenticator.php';

$ga = new PHPGangsta_GoogleAuthenticator();

$secret = 'mysecretkey1209312310293';

echo "Secret is: ".$secret."\n\n";

//not sure if this qrCodeUrl thing matters
$qrCodeUrl = $ga->getQRCodeGoogleUrl('my@google.com', $secret); 

echo "Google Charts URL for the QR-Code: ".$qrCodeUrl."\n\n";

$oneCode = $ga->getCode($secret);

echo "Checking Code '$oneCode' and Secret '$secret':\n";

$checkResult = $ga->verifyCode($secret, $oneCode, 2);    // 2 = 2*30sec clock tolerance
if ($checkResult) {
    echo 'OK';
} else {
    echo 'FAILED';
}

0 个答案:

没有答案