vinnyvicente / google-authenticator
Google Authenticator 的 PHP 仓库
v1.1
2018-11-07 14:01 UTC
Requires
- php: >=5.6
- christian-riesen/base32: 1.2
- zendframework/zend-math: >=2.2
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is auto-updated.
Last update: 2024-09-08 08:03:04 UTC
README
简介
这是一个将网站与 Google Authenticator 集成的模块。
要求
- ChristianRiesen/base32 (1.2)
- zendframework/zend-math (>2.2.*)
安装
- 在您的 composer.json 中添加此项目
"require": { "vinyvicente/google-authenticator": "1.1" }
- 现在运行以下命令让 composer 下载仓库
$ php composer.phar update
使用方法
### 第一步 - 注册应用
显示二维码和表单
$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 }
### 第二步 - 登录时验证代码
$google = new GoogleAuthenticator($user->getSecretKey()); $userSubmitCode = $_POST['codeFoo']; // Verify Code if ($google->verifyCode($userSubmitCode)) { // OK - allowed login }