hxm /2fa
一次性密码认证包。
1.0.1
2021-10-26 10:18 UTC
Requires
- bacon/bacon-qr-code: ^2.0
- pragmarx/google2fa: ^8.0
This package is auto-updated.
Last update: 2024-09-27 08:37:43 UTC
README
一次性密码认证包。
安装
-
该包发布一个 config/hxm2fa.php 文件。如果您已经有一个同名文件,您必须重命名或删除它。
-
您可以通过 composer 安装该包
composer require hxm/2fa
-
运行迁移
php artisan migrate
-
您应该使用以下命令发布模板视图和 config/hxm2fa.php 配置文件
php artisan vendor:publish --provider=HXM2FA\ServiceProvider
-
默认配置文件内容
// ... return [ 'enabled' => true, 'show_secret' => false, 'route' => [ 'prefix' => 'user' ], 'extend_layout' => 'layouts.app', 'encrypt_secret' => true, /*customer QR style*/ 'qr_code' => [ 'size' => 192, 'margin' => 0, 'background' => [ 'red' => 255, //red the red amount of the color, 0 to 255 'green' => 255, //green the green amount of the color, 0 to 255 'blue' => 255 //blue the blue amount of the color, 0 to 255 ], 'fill' => [ 'red' => 45, //red the red amount of the color, 0 to 255 'green' => 55, //green the green amount of the color, 0 to 255 'blue' => 72 //blue the blue amount of the color, 0 to 255 ], ] ];
基本用法
-
首先,将 HXM2FA\TwoFactorAuthenticatable 特性添加到您的 User 模型中
use Illuminate\Foundation\Auth\User as Authenticatable; use HXM2FA\TwoFactorAuthenticatable; class User extends Authenticatable { use TwoFactorAuthenticatable; // ... }
-
我们提供了一个具有静态函数的 Facade,以执行有用功能
use HXM2FA\Facades\HXM2FA; // ... /*to generate Secret*/ $secret = HXM2FA::generate2FASecret(); /*to generate QrCode html*/ HXM2FA::getQrCode(string $company, string $holder, string $secret) /*to verify code*/ HXM2FA::verifyCode(string $secret, string $code) /*To get instance of \PragmaRX\Google2FA\Google2FA */ HXM2FA::getGoogle2FA(); // ...