delboy1978uk / google-auth
谷歌验证器双因素认证
v1.0.4
2017-11-23 12:19 UTC
Requires
- php: >=5.3
Requires (Dev)
- codeception/codeception: ^2.3
This package is auto-updated.
Last update: 2024-09-04 21:39:06 UTC
README
这个PHP类可以用于与谷歌验证器移动应用进行交互,以实现双因素认证。此类可以生成密钥、生成验证码、验证验证码并展示用于扫描密钥的二维码。它遵循RFC6238实现TOTP。
为了安全安装,您必须确保使用的代码不能被重用(重放攻击)。您还需要限制验证次数,以抵御暴力攻击。例如,您可以限制一个IP地址(或IPv6块)在10分钟内最多尝试10次验证。这取决于您的环境。
从PHPGangsta的lib分支而来 - 请参阅版权声明。
安装
通过composer进行安装
composer require delboy1978uk/google-auth
使用
请参考以下示例
<?php use Del\Auth\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
$checkResult
是一个布尔值,true/false。运行脚本会提供以下输出
Secret is: OQB6ZZGYHCPSX4AK
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
Checking Code '848634' and Secret 'OQB6ZZGYHCPSX4AK':
OK