whyounes / laravel-two-factor-auth
Laravel 双因素认证
v1.0.0
2016-12-21 15:36 UTC
Requires
- php: ^5.5.9 || ^7.0
- illuminate/auth: 5.1.* || 5.2.* || 5.3.*
- illuminate/config: 5.1.* || 5.2.* || 5.3.*
- illuminate/database: 5.1.* || 5.2.* || 5.3.*
- illuminate/events: 5.1.* || 5.2.* || 5.3.*
- twilio/sdk: ^5.4
Requires (Dev)
- mockery/mockery: ~0.9.4
- orchestra/testbench: ~3.0
- phpunit/phpunit: ^4.8 || ^5.0
This package is auto-updated.
Last update: 2024-08-29 03:36:48 UTC
README
Laravel 5.3+ 的双因素认证
安装
使用 Composer 将包添加到您的项目中
composer require whyounes/laravel-two-factor-auth
发布包资源
php artisan vendor:publish
运行迁移
php artisan migrate
将其添加到您提供者列表中
// config/app.php // ... 'providers' => [ // ... Whyounes\TFAuth\TwoFAProvider::class, };
将 TFAuthTrait
特性添加到您的用户模型中
// app/User.php class User extends Authenticatable { use \Whyounes\TFAuth\Models\TFAuthTrait; // ... }
配置
您只能设置两个配置
delete_verification_code_after_auth
: 如果您希望在登录后删除未使用的验证码,则将其设置为true
。verification_code_length
: 验证码的长度。
验证码发送者
默认情况下,该包使用 Twilio 发送验证码(短信和电话)。您可以轻松地按如下方式更改它
use Whyounes\TFAuth\Contracts\VerificationCodeSenderInterface; class MyService implements VerificationCodeSenderInterface { public function sendCodeViaSMS($code, $phone, $message = "Your verification code is %s") { // Send code and return boolean for status } public function sendCodeViaPhone($code, $phone, $message = "Your verification code is %s") { // Send code and return boolean for status } }
接下来我们应该在容器中切换实现
use Whyounes\TFAuth\Contracts\VerificationCodeSenderInterface; class AppProvider extends ServiceProvider { public function register() { // ... $this->app->bind(VerificationCodeSenderInterface::class, MyService::class); } }
这就对了,您的新服务将被用于发送验证码。如果您添加新的服务实现,您可以提交一个新的拉取请求,我将将其添加到包中 :)
示例
查看 这个存储库 以使用该包的演示应用程序。