adevesa/laravel-simple-otp

Generate and validate OTPs for your applications

1.0.2 2024-01-31 20:16 UTC

This package is auto-updated.

Last update: 2024-04-29 14:00:31 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.