creatvstudio / laravel-otp
A Laravel package that handles Time based OTP
Requires
- php: ^7.1
- illuminate/support: ^7.0
- spomky-labs/otphp: ^10.0
Requires (Dev)
- orchestra/testbench: ^5.0
- phpunit/phpunit: ^8.0|^9.0
This package is auto-updated.
Last update: 2024-10-24 19:13:56 UTC
README
This package is still in alpha stage. A laravel package to implement timebased otp.
Installation
You can install the package via composer:
composer require creatvstudio/laravel-otp
Publish package
php artisan vendor:publish --provider="CreatvStudio\Otp\OtpServiceProvider"
Run the migrations
php artisan migrate
Add to your config/app.php
aliases => [ ... 'Otp' => \CreatvStudio\Otp\Facades\Otp::class, ... ],
Set your mail settings from .env
file
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
Publish config file using the following command:
php artisan vendor:publish --tag="otp-config"
Usage
Add trait to your User class
use CreatvStudio\Otp\HasOtp; class User extends Authenticable { use Notifiable; use HasOtp; } // Generate an OTP $otp = $user->getOtpCode(); // Verify an OTP $user->verifyOtp($otp);
Protecting routes
Add the following codes to $routeMiddleware
of app/Http/Kernel.php
protected $routeMiddleware = [ ... 'otp' => \CreatvStudio\Otp\Http\Middleware\CheckOtpSession::class, ]
Use to your routes/web.php
Otp::routes(); Route::middleware(['auth'])->group(function(){ Route::get('otp-protected')->middleware('otp'); });
Note: Default Laravel Authentication is required to make the otp routes work properly.
Customizing sending of OTP Code to Mail
To customize the contents of email when sending OTP Code, just modify ./app/Notifications/SendOtpNotification.php
Note: Please refer to Official Laravel Documentation for custom notifications.
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email jeff@creatvstudio.ph instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.