Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stanfortonski/laravel-twofactor
Two-factor authentication package for Laravel 7.x, 8.x
https://github.com/stanfortonski/laravel-twofactor
authorization laravel laravel-7 laravel-7-package laravel-8 laravel-8-package laravel-framework laravel-package package two-factor two-factor-auth two-factor-authentication
Last synced: 14 days ago
JSON representation
Two-factor authentication package for Laravel 7.x, 8.x
- Host: GitHub
- URL: https://github.com/stanfortonski/laravel-twofactor
- Owner: stanfortonski
- License: mit
- Created: 2021-01-30T19:40:06.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-15T11:49:22.000Z (almost 4 years ago)
- Last Synced: 2024-12-09T02:07:36.005Z (14 days ago)
- Topics: authorization, laravel, laravel-7, laravel-7-package, laravel-8, laravel-8-package, laravel-framework, laravel-package, package, two-factor, two-factor-auth, two-factor-authentication
- Language: PHP
- Homepage: https://packagist.org/packages/stanfortonski/laravel-twofactor
- Size: 31.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel-Twofactor
Two-factor authentication package for Laravel 7.x and 8.x via e-mail.# Information
This package provides you to set of middleware, view, migration, routes with controllers, transaltions and methods to user model which allow you to set up 2FA vie email for your application.# Installation
1. First install package via composer. Run `composer require stanfortonski/laravel-twofactor`.
2. Setup provider. In config/app.php add following code to bottom of providers:
```php
'providers' => [
//...
Stanfortonski\Laraveltwofactor\ServiceProvider::class
],
```
3. Setup middleware. In app/Http/Kernel.php add following code to bottom of middlewares:
```php
protected $routeMiddleware = [
//...
'twofactor' => \Stanfortonski\Laraveltwofactor\Middleware\TwoFactor::class
];
```
5. Use \Stanfortonski\Laraveltwofactor\Traits\TwoFactorable trait in User class with \Illuminate\Notifications\Notifiable. Snippet: `use Notifiable, TwoFactorable;`
4. You have to publish config file twofactor.php. Run command: `php artisan vendor:publish --provider="Stanfortonski\Laraveltwofactor\ServiceProvider"`.
5. Run `php artisan migrate`.
6. Add line `$user->startTwoFactor()` in your login process. For example in Laravel/ui add this line in Auth\LoginController@authenticated method before redirect.
7. Set up your email in .env.# Configuration
In config/twofactor.php
1. If you want to disable twofactor/preferences routes set `preferences.allow` to false.
2. If you want to change expire time of 2FA code you will change `expire_duration`. Default value is 15 minutes.
3. Look at routes.login, routes.successful and routes.return that must be real routes name in your application. More in file itself.# Usage
You have to set twofactor middleware in routes. The way depends on you.Example:
```php
Route::get('/home', function(){
return view('home');
})->middleware(['auth', 'twofactor']);
```