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 '认证失败';
}
相关推荐
zzzll11112 小时前
Claude Code离线安装方案揭秘
开发语言·php
Ai拆代码的曹操3 小时前
Nginx upstream keepalive 连接池中毒排查实录
chrome·nginx·php
wling03013 小时前
vasp虚频计算-python脚本
开发语言·windows·python·vasp计算
郝学胜-神的一滴3 小时前
Qt 高级编程 040:按钮悬浮弹出滑块弹窗的完整攻略
开发语言·c++·qt·软件工程·用户界面
xrandzj4 小时前
Python面向对象编程入门:类、实例、初始化与封装实践
开发语言·python
DLYSB_5 小时前
API 网关流量洪峰与突发 CC 攻击:我用 Go 写了个“现场物理防御哨兵”,把故障响应压缩到秒级
开发语言·后端·golang·报警灯
雨田言炎7 小时前
四、关于Qt项目需要知道的
开发语言·笔记·qt
程序喵大人8 小时前
【C++进阶】STL算法与函数对象 - 02 sort为什么需要随机访问迭代器
开发语言·c++·算法
SomeB1oody8 小时前
【RustyML入门】2.6. 线性判别分析
开发语言·后端·机器学习·rust·教程
用户昵称1009 小时前
C/C++编程-工程实践-本地存储log的工程意义
c语言·开发语言