dukstra / otp
A Laravel package for generating, validating and handling OTPs
Installs: 357
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:plugin
Requires
- php: ^7.4|^8.0
- illuminate/contracts: ^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3
- vimeo/psalm: ^3.11|^4.3
README
Installation
You can install the package via composer:
composer require dukstra/otp
You can publish and run the migrations with:
php artisan vendor:publish --provider="Dukstra\Otp\Providers\OtpServiceProvider" --tag="migrations" php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="Dukstra\Otp\Providers\OtpServiceProvider" --tag="config"
Usage
use Dukstra\Otp\Otp; . . $otp = Otp::generate($identifier); . $verify = Otp::validateUsingIdentifier($identifier, $otp->token); // example response { "status": true "message": "OTP is valid" } // to get an expiredAt time $expires = Otp::expiredAt($identifier); // example response { +"status": true +"expired_at": Illuminate\Support\Carbon @1611895244^ { .... #dumpLocale: null date: 2021-01-29 04:40:44.0 UTC (+00:00) }
You have control to update the setting at otp-generator.php config file, but you can also control while generating.
Advance Usage
use Dukstra\Otp\Otp; . . $otp = Otp::setValidity(30) // otp validity time in mins ->setLength(4) // Length of the generated otp ->setMaximumOtpsAllowed(10) // Number of times allowed to regenerate otps ->setOnlyDigits(false) // generated otp contains mixed characters ex:ad2312 ->setUseSameToken(true) // if you re-generate OTP, you will get same token ->generate($identifier); . $verify = Otp::setAllowedAttempts(10) // number of times they can allow to attempt with wrong token ->validateUsingIdentifier($identifier, $otp->token);
Testing
composer test
Credits
License
The MIT License (MIT).