egately / egate-otp
OTP Mangement Package
Requires
- php: ^8.1|^8.2|^8.3|^8.4
- bacon/bacon-qr-code: ^2.0 ||^3.0
- illuminate/contracts: ^9.0 ||^10.0 ||^11.0 || ^12.0
- illuminate/support: ^8.82 || ^9.0 ||^10.0 ||^11.0 ||^12.0
- pragmarx/google2fa: ^7.0 ||^8.0
- spatie/laravel-package-tools: ^1.14.0 || ^1.16
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9 ||^8.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0 ||^3.0
- pestphp/pest-plugin-arch: ^2.0 ||^3.0
- pestphp/pest-plugin-laravel: ^2.0 ||^3.0
README
This package is used to generate and manage OTP's for users, it can be used to generate OTP's for any model you want.
What makes this package different from other OTP packages?
The special feature of this package is that the OTP generated by extending google2fa, this means that the OTP generated by this package can be used with any authenticator app.
- You can use any authenticator app to scan the QR code generated by this package and use it to validate OTP's for your users, the same way you use google2fa you can use this package.
- Since we can generate the OTP's for any model you want, you can send the OTP generated by SMS or Email to your users. and they can use it to validate their accounts.
- This is very handy if you want to use OTP's for your users but you don't want to use the authenticator app. Or give your users the option to use authenticator or receive the OTP in sms.
- Authenticator OTP's expire in half a minute, but the OTP's generated by this package expire in any specified number of minutes, You can have a valid OTP for the last five minutes.
- If you use the authenticator to authenticate the QR code generated by this package, you can use the same QR code to authenticate the OTP's generated by this package.
- If You revcive by Email or Sms, it natuarly takes longer than half a minute to receive the OTP, so you can use the same received code to authenticate the OTP's generated by this package, since it is valid for the specified minutes.
Installation
You can install the package via composer:
composer require egately/egate-otp
You can publish and run the migrations with:
php artisan vendor:publish --tag="egate-otp-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="egate-otp-config"
This is the contents of the published config file:
return [ 'app_name' => env('APP_NAME'), // this will be used for the title of the authenticator account 'default_identifier_attribute' => 'email', // the default attribute to be used as the identifier to be added to the authenticator account 'otp_length' => 6, // the length of the generated otp it is 6 by default 'default_validation_window' => 5,// the minutes before the otp expires ];
Usage
Add the trait to your User model(s) or any other model you want to use for OTP's
use Egate\EgateOtp\Traits\HasEgateOtp;
Once the trait is used in the model you can use the following methods ( example below is for User model )
- Generate New OTP : this will generate a new otp
$otp = $user->generateOtp();
- Validate OTP : this will validate the otp
// result is true or false, the window is the number of minutes before the otp expires, if not specified the default window will be used $Vlaidation = $user->ValidateOtp($otp, $window = null);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.