ramprasadm1986/yii2-google-authenticator

Yii 2 扩展,用于 Google Authenticator

1.0.1 2022-01-03 12:47 UTC

This package is auto-updated.

Last update: 2024-09-29 06:20:24 UTC


README

GitHub tag GitHub tag GitHub tag

此 PHP 类可用于与 Google Authenticator 移动应用程序进行交互以实现双因素认证。该类可以生成密钥,生成代码,验证代码并显示用于扫描密钥的 QR 码。它根据 RFC6238 实现了 TOTP。

为了安全安装,您需要确保使用过的代码不能被重复使用(重放攻击)。您还需要限制验证次数,以抵抗暴力攻击。例如,您可以限制一个 IP 地址(或 IPv6 块)在 10 分钟内最多尝试 10 次验证。这取决于您的环境。

安装

composer require ramprasadm1986/yii2-google-authenticator

配置

'authenticator' => [
    'class' => 'ramprasadm1986\Authenticator\GoogleAuthenticator'
]

使用示例

$authenticator = \Yii::$app->authenticator;

//Google Authenticator Secret
$secret = $authenticator->secret;

//Google Charts URL for the QR-Code
$authenticator->secret = $secret;
$authenticator->name = 'EXAMPLE';
$qRCodeGoogleUrl = $authenticator ->qRCodeGoogleUrl;

//Code
$code = $authenticator->code;
$authenticator->verifyCode($code); //return bool