mincdev/php-otpauth

生成双因素认证二维码的库

1.0.1 2021-10-19 07:53 UTC

This package is auto-updated.

Last update: 2024-09-22 11:54:46 UTC


README

一个库,用于生成与 Google Authenticator、Authy 等一起使用的双因素认证二维码

安全生成 QRCode

由于二维码是在您的服务器上本地生成的,因此此库具有安全的 QRCode 生成功能。这意味着用户的密钥不会传递给任何第三方或远程服务器以生成代码。这受到了 kravietz这里 看到的 stack overflow 答案的启发

安装(Composer)

composer require mincdev/php-otpauth

依赖项

此库需要位于 https://github.com/tecnickcom/tc-lib-barcodetc-lib-barcode 库。

注意:tc-lib-barcode 库由一个独立的实体维护和拥有。

生成 QRCode

您可以使用以下方法生成可由 Google Authenticator、Authy 等扫描的 QRCode。

$otpAuth = new OtpAuthenticator();

$userName = "MrDoe";
$appName = "My Awesome App";

// Store this secret somewhere safe, as you'll need it to validate the pin later
$userSecret = $otpAuth->newSecret();

$qrBase64 = $otpAuth->getQR($userName, $appName, $userSecret);

验证 PIN

一旦用户登录,您可以使用以下方法验证他们的 PIN。

$otpAuth = new OtpAuthenticator();
$isValid = $otpAuth->validate($userSecret, $pinCode);