<?php
require_once 'PHPGangsta/GoogleAuthenticator.php'; //引入类库
$ga = new PHPGangsta_GoogleAuthenticator();
$secret = $ga->createSecret();
//创建一个密钥,将密钥先进行存储
echo "Secret is: ".$secret."\n\n";
//Secret is: OQB6ZZGYHCPSX4AK
//getQRCodeGoogleUrl('要加密的标识',生成的密钥)
//这样就可以进行绑定
$qrCodeUrl = $ga->getQRCodeGoogleUrl('Blog', $secret);
echo "Google Charts URL for the QR-Code: ".$qrCodeUrl."\n\n";
//Google Charts URL for the QR-Code: https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/infoATphpgangsta.de%3Fsecret%3DOQB6ZZGYHCPSX4AK
//PS:谷歌会直接返回一个二维码 使用Authenticator扫描即可绑定
//getCode('生成的密钥')
$oneCode = $ga->getCode($secret);
echo "Checking Code '$oneCode' and Secret '$secret':\n";
//Checking Code '848634' and Secret 'OQB6ZZGYHCPSX4AK':
//$oneCode 服务器一次性验证 返回的验证数字
//verifyCode('生成密钥','一次性验证码',2) //2: 2*30=60秒误差
$checkResult = $ga->verifyCode($secret, $oneCode, 2);
if ($checkResult) {
echo 'OK';
} else {
echo 'FAILED';
}
PHP接入谷歌验证器(Google Authenticator)
最新推荐文章于 2024-09-26 17:11:18 发布