fanwei / googleauthenticator
psr4 Google Authenticator 双因素认证
v1.0.0
2020-08-11 08:14 UTC
Requires
- php: >=5.3
This package is auto-updated.
Last update: 2024-09-11 16:52:47 UTC
README
- 版权所有(c)2012-2016, http://www.phpgangsta.de
- 作者:Michael Kliewe,@PHPGangsta 及其他 贡献者
- 许可协议:BSD许可证。
此PHP类可用于与Google Authenticator移动应用程序进行交互,以实现双因素认证。此类可以生成密钥、生成代码、验证代码并显示用于扫描密钥的二维码。它根据RFC6238实现TOTP。
为了安全安装,您必须确保使用的代码不能被重用(重放攻击)。您还需要限制验证次数,以抵御暴力攻击。例如,您可以限制一个IP地址(或IPv6块)在10分钟内的验证次数为10次。这取决于您的环境。
用法
请参考以下示例
composer require "fanwei/googleauthenticator:1.0.*"
<?php use Fanwei\GoogleAuthenticator\GoogleAuthenticator; $ga = new GoogleAuthenticator(); // 创建 $secret = $ga->createSecret(); // 获取 code $code = $ga->getCode($secret); // 验证 code $res = $ga->verifyCode($secret, $code); // 获取二维码字符串 $qrcodeString = $ga->getQrcodeString($secret, 'GoogleAuthenticator');
运行脚本将提供以下输出
Secret is:WLRAQ5KGUC7YCR75
Code is:577963
res:true
qrcodeString:otpauth://totp/GoogleAuthenticator?secret=WLRAQ5KGUC7YCR75