truesocialmetrics / google-authenticator
PHP版本的Google Authenticator仓库
1.3.0
2020-04-03 08:08 UTC
Requires
- php: >=7.4
- christian-riesen/base32: *
- laminas/laminas-math: *
This package is auto-updated.
Last update: 2024-08-29 05:22:25 UTC
README
[已弃用] 请使用antonioribeiro/google2fa代替!
简介
这是一个用于将网站与Google Authenticator集成的模块。
要求
- ChristianRiesen/base32 (1.2)
- zendframework/zend-math (>2.2.*)
安装
- 将此项目添加到您的composer.json中
"require": { "leandrolugaresi/google-authenticator": "1.0.*" }
- 现在运行以下命令让composer下载仓库:
$ php composer.phar update
用法
步骤 1 - 注册应用程序
显示二维码和表单
$googleAuth = new \GoogleAuthenticator\GoogleAuthenticator(); $googleAuth->setIssuer('YourApplicationName'); //save the secretKey to register after $_SESSION['secretKeyTemp'] = $googleAuth->getSecretKey(); // Show the qrcode to register //this param is an identifier of the user in this application echo $googleAuth->getQRCodeUrl($user->username.'@YourApplicationName');
验证表单中的代码并保存此用户的secretKey
$google = new GoogleAuthenticator($_SESSION['secretKeyTemp']); $userSubmitCode = $_POST['codeFoo']; if ($google->verifyCode($userSubmitCode)) { //save the secretKey of this user }
步骤 2 - 登录时验证代码
$google = new GoogleAuthenticator($user->getSecretKey()); $userSubmitCode = $_POST['codeFoo']; // Verify Code if ($google->verifyCode($userSubmitCode)) { // OK - aloowed login }