shali / ydb-think-2fa
this is a two factor auth tool for thinkphp 5,6.
1.0.2
2025-05-29 06:05 UTC
Requires
- php: ^7.2.0
This package is not auto-updated.
Last update: 2025-05-30 01:20:22 UTC
README
think-2fa 是一个基于 Google Authenticator 的两步验证插件,基于 tp6 框架开发。
2fa 算法库来自 https://github.com/PHPGangsta/GoogleAuthenticator。
安装要求
- tp6
- 已经配置平台名称 app.app_name
- 存在代理后台 token 拦截器 \app\admin\middleware\AdminTokenMiddleware
- 存在代理模型 app\common\model\agent\Agent
数据库安装
执行 shali/ydb-think-2fa/database
目录下的 sql 脚本,创建 2fa 代理密钥表。
服务端安装
composer require shali/ydb-think-2fa
前端安装
vue 组件使用。
复制服务端插件目录 shali/ydb-think-2fa/src/view/admin
下的 2fa.vue
到项目目录下。
通过组件来使用。
<el-dialog title="升级更安全的两步验证" :visible.sync="totp.visible" width="80%">
<two-factor-auth />
</el-dialog>
使用
为了方便大家使用,我增加了 TwoFactorAuth
门面,保证与 think 框架的集成统一。
- 生成密钥
$secret = TwoFactorAuth::genSecret();
- 创建二维码
$qrCode = TwoFactorAuth::getQrCode($secret, '18888888888', '广州最大的POS平台');
- 验证验证码
$result = TwoFactorAuth::verify($secret, '123456');