# thinkphp扩展2fa **Repository Path**: goodbugood/ydb-think-2fa ## Basic Information - **Project Name**: thinkphp扩展2fa - **Description**: ydb 项目 2fa 功能插件,你也可以当做单纯的 2fa 工具。 - **Primary Language**: PHP - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-29 - **Last Updated**: 2025-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # think-2fa think-2fa 是一个基于 Google Authenticator 的两步验证插件,基于 tp6 框架开发。 2fa 算法库来自 https://github.com/PHPGangsta/GoogleAuthenticator。 ## 安装要求 1. tp6 2. 已经配置平台名称 app.app_name 3. 存在代理后台 token 拦截器 \app\admin\middleware\AdminTokenMiddleware 4. 存在代理模型 app\common\model\agent\Agent ### 数据库安装 执行 `shali/ydb-think-2fa/database` 目录下的 sql 脚本,创建 2fa 代理密钥表。 ### 服务端安装 ```php composer require shali/ydb-think-2fa ``` ### 前端安装 vue 组件使用。 复制服务端插件目录 `shali/ydb-think-2fa/src/view/admin` 下的 `2fa.vue` 到项目目录下。 通过组件来使用。 ```vue ``` ## 使用 为了方便大家使用,我增加了 `TwoFactorAuth` 门面,保证与 think 框架的集成统一。 - 生成密钥 ```php $secret = TwoFactorAuth::genSecret(); ``` - 创建二维码 ```php $qrCode = TwoFactorAuth::getQrCode($secret, '18888888888', '广州最大的POS平台'); ``` - 验证验证码 ```php $result = TwoFactorAuth::verify($secret, '123456'); ```