Download the PHP package morcen/laravel-otp-generator without Composer
On this page you can find all versions of the php package morcen/laravel-otp-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download morcen/laravel-otp-generator
More information about morcen/laravel-otp-generator
Files in morcen/laravel-otp-generator
Package laravel-otp-generator
Short Description Generate OTP for your Laravel application
License MIT
Homepage https://github.com/morcen/laravel-otp-generator
Informations about the package laravel-otp-generator
Generate OTP for your Laravel application
This package requires Laravel >= 8.x.
Installation
-
Install the package via composer:
-
Publish the config file with:
Open
config/otp.phpand update the following:identifier- this is what this package will use to query for the OTP record in the databaseset- this defines the characters that will be used for the code. Possible values are:numbers- from zero to nine (0 to 9)lowercase- English alphabet fromatozuppercase- English alphabet fromAtoZothers- defaults to empty string. You can put any other characters you wish to see as part of the OTP code.all- uses all letters and numbers, including the characters inothersoption. This is the defualt option.
lifetime- defines how long the OTP will be valid for. Default is15minutes.length- defines the default length of the OTP. Though this can be simply overriden whenever thegenerateorgenerateFormethods are called. Default length is4.encrypt- if set totrue, it will have additional propertyhashin the returned object. If used withgenerateFor()method, the value that will be saved in the database will be the encrypted value. Available sincev1.1.0.alg- This will be the hashing algorithm used for the OTP code. This will only take effect ifencryptis set totrue. Valid options aresha1andmd5. Available sincev1.1.0.
-
Publish the migrations with:
and update it to include the
identifierfield mentioned in the previous step. For example, if you havein your
config/otp.php, you have to add this line in the migration file created: - Run the migrations with:
Usage
To generate an OTP that can be validated afterwards, use the method generatedFor(). It accepts two parameters:
$identifierValue(required) - the value that will be matched against theidentifier$length(optional) - the length of the code to use. If this is not provided, it will use the defaultlengthoption set inconfig/otp.php.
For example, we want to create an OTP for the email [email protected]:
$otp receives back the OTP object*, e.g.
And then to validate, use the method validateFor, accepting the $identifierValue and the OTP as parameters and returns bool:
*NOTE: hash property only appears in the OTP object if encrypt is set to true.
To generate and receive an OTP code only:
$otp receives back just the OTP object like this:
*NOTE: hash property only appears in the OTP object if encrypt is set to true.
To override the default length of the OTP, pass the length as a parameter. For example, to generate an OTP that is 10 characters long:
or
Testing
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
- Morcen
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-otp-generator with dependencies
spatie/laravel-package-tools Version ^1.9.2
laravel/framework Version ^8.0 | ^9.0