adevesa / laravel-simple-otp
Generate and validate OTPs for your applications
Fund package maintenance!
adevesa
Installs: 1 164
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- illuminate/contracts: ^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
README
This package is a simple OTP generator for Laravel. You can use it to generate OTPs and validate them.
Installation
You can install the package via composer:
composer require adevesa/laravel-simple-otp
You can publish and run the migrations and publish the config file with:
php artisan vendor:publish --provider="adevesa\SimpleOTP\SimpleOTPServiceProvider"
php artisan migrate
This is the contents of the published config file:
return [ 'otp_length' => env('SIMPLE_OTP_LENGTH', 6), 'otp_format' => env('SIMPLE_OTP_FORMAT', 'alpha_numeric'), 'otp_expiration_minutes' => env('SIMPLE_OTP_EXPIRATION_MINUTES', 5), 'otp_max_attempts' => env('SIMPLE_OTP_MAX_ATTEMPTS', 3), 'otp_throw_exceptions' => env('SIMPLE_OTP_THROW_EXCEPTIONS', true), ];
With the otp_throw_exceptions
option you can control if the package should throw exceptions or return false
when an OTP is not valid.
Usage
$simpleOTP = new adevesa\SimpleOTP(); $code = $simpleOTP->create('a_email@example.com'); $simpleOTP->verify('a_email@example.com', "ASD123");
Or also
$code = \adevesa\SimpleOTP\Facades\SimpleOTP::create('+5491123456789')->code; $isValid = \adevesa\SimpleOTP\Facades\SimpleOTP::verify('+5491123456789', $code);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
If you discover any security-related issues, please email adevesa95@outlook.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.