wayhood/googleauthenticator

谷歌身份验证器 2 步验证

dev-master 2014-12-01 02:02 UTC

This package is auto-updated.

Last update: 2024-09-07 17:28:07 UTC


README

谷歌身份验证器 2 步验证

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一:

php composer.phar require --prefer-dist wayhood/googleauthenticator "*"

或者添加

"wayhood/googleauthenticator": "*"

到您的 composer.json 文件的 require 部分。

使用方法

一旦安装了此扩展,只需在您的代码中通过

use wh/googleauthenticator/GoogleAuthenticator';

$ga = new GoogleAuthenticator();

$secret = $ga->createSecret();
echo "Secret is: ".$secret."\n\n";

$qrCodeUrl = $ga->getQRCodeGoogleUrl('Blog', $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';
}