PHP基于Google Authenticator双因素身份验证实现动态码验证

一:介绍

Google Authenticator双因素身份验证是谷歌推出的一款动态口令工具,解决大家各平台账户遭到恶意攻击的问题,一般在相关的服务平台登陆中除了用正常用户名和密码外,需要再输入一次谷歌认证器生成的动态口令才能验证成功,相当于输入二次密码,以达到账户的高安全性。

二:拓展安装

复制代码
composer require huaweichenai/google-authenticator

三:使用

1:创建密钥

复制代码
$authenticator = new Authenticator();
$secret = $authenticator->createSecret();

2:获取手机端扫描二维码链接

复制代码
$authenticator = new Authenticator();
$qrCodeUrl  = $authenticator->getQRCodeGoogleUrl('username', $secret, 'title');

3:获取手机端扫描二维码的信息

复制代码
$authenticator = new Authenticator();
$authCode  = $authenticator->getAuthCode('username', $secret, 'title');
$authCode = urldecode($authCode);//使用此信息生成二维码

4:动态口令认证

复制代码
$authenticator = new Authenticator();
$verifyCode  = $authenticator->verifyCode($secret, 'code验证码');
if ($verifyCode) {
  echo '认证成功';
} else {
  echo '认证失败';
}
相关推荐
逐步前行1 分钟前
C标准库--C99--布尔型<stdbool.h>
c语言·开发语言
QX_hao1 分钟前
【Go】--闭包
开发语言·golang
java_logo3 小时前
Docker 部署 WordPress 全流程
运维·docker·容器·word·php·1024程序员节
林月明3 小时前
【VBA】自动设置excel目标列的左邻列格式
开发语言·excel·vba·格式
喜欢吃燃面4 小时前
数据结构算法题:list
开发语言·c++·学习·算法·1024程序员节
。TAT。4 小时前
C++ - 多态
开发语言·c++·学习·1024程序员节
武当豆豆4 小时前
C++编程学习(第42天)
开发语言·c++·学习
yong99905 小时前
基于MATLAB的内容图像检索实现
开发语言·matlab
歪歪1005 小时前
在C#中详细介绍一下Visual Studio中如何使用数据可视化工具
开发语言·前端·c#·visual studio code·visual studio·1024程序员节
jdlxx_dongfangxing5 小时前
C++ STL 容器与算法详解
开发语言·c++·1024程序员节