nsp-team/google-authenticator

Google Authenticator

v0.0.1 2021-12-01 23:50 UTC

This package is auto-updated.

Last update: 2024-09-17 06:41:26 UTC


README

这是一个PHP库,PHP中的Google Authenticator一次性密码算法

  1. 相对于验证码,安全性更高;几乎不存在被破解的方法
  2. 验证码有时候无法识别,操作不方便
  3. 一机一码,不存在账号被盗用的问题
  4. 动态验证,每30秒生成一个验证码,安全性更有保障

参见:https://www.phpgangsta.de/2-faktor-authentifizierung-mit-dem-google-authenticator

安装

此库可以通过composer安装 composer require nsp-team/google-authenticator

使用

require_once "vendor/autoload.php";

use NspTeam\Authenticator\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';
}