aventusgroup/google2fa

1.0.2 2024-07-25 12:50 UTC

This package is not auto-updated.

Last update: 2024-09-19 13:46:23 UTC


README

安装

composer require aventusgroup/google2fa

用法

  1. 为每个用户都需要创建并保存密钥(检查代码时将需要此密钥)。
  2. $secret = TwoFactor::generateSecretKey(); // 16位字符串
  3. 为用户生成二维码(在方法中传入之前创建的密钥,以及将在应用程序中显示的公司名称和用户名)
  4. $qrContent = TwoFactor::generateQr($secret, 'CompanyName', 'UserName'); // 图像的base64内容
  5. 显示图片
  6. 下载手机应用程序(android https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en,ios https://apps.apple.com/us/app/google-authenticator/id388497605
  7. 在应用程序中点击 +,通过二维码添加
  8. 应用程序将生成有效的6位数代码,这些代码每60秒更新一次
  9. 每次用户登录时,都需要接受此代码并验证它
  10. TwoFactor::checkCode($code, $secret) // 其中 $code 是客户端应用程序中的代码,$secret 是为客户端保存的密钥。如果代码正确,则为True。如果代码错误,则为False