Download the PHP package officialozioma/otp-generator without Composer
On this page you can find all versions of the php package officialozioma/otp-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download officialozioma/otp-generator
More information about officialozioma/otp-generator
Files in officialozioma/otp-generator
Package otp-generator
Short Description Laravel OTP generator and validation
License MIT
Homepage https://github.com/officialOzioma/OTP-generator
Informations about the package otp-generator
OTP Generator
Introduction
This is Laravel package for generation One Time Password (OTP) generator and validation. This is done on the cache it supported all the laravel cache drivers: "apc", "array", "database", "file", "memcached", "redis"
Installation
Install via composer
Add Service Provider & Facade
For Laravel 5.5+
Once the package is added, the service provider and facade will be auto discovered.
For Laravel 5.2 / 5.3 / 5.4
Add the ServiceProvider to the providers array in config/app.php
:
Add the Facade to the aliases array in config/app.php
:
Configuration
Publish config and language file
This package publishes an otp.php
file inside your applications's config folder which contains the settings for this package. Most of the variables are bound to environment variables, you may add Key-Value pair to the .env
file in the Laravel application.
Usage
Generate OTP
$identifier
: The identity that will be tied to the OTP.
Sample
This will generate a OTP that will be valid for 15 minutes.
Validate OTP
$identifier
: The identity that is tied to the OTP.$password
: The password tied to the identity.
Sample
Responses
On Success
Invalid OTP
Expired
Max attempt
- Reached the maximum allowed attempts, default 10 times with each identifier
Validate OTP by Laravel Validation
Validate OTP by session id
- The setting without identifier will automatically use the session ID as the default, and the OTP generation and verification will be completed in same session (browser's cookies).
Advanced Usage
Generate OTP with options
setLength($length)
: The length of the password. Default: 6setFormat($format)
: The format option allows you to decide which generator implementation to be used when generating new passwords. Options: 'string','numeric','numeric-no-zero','customize'. Default: "numeric"setExpires($minutes)
: The expiry time of the password in minutes. Default: 15setRepeated($boolean)
: The repeated of the password. The previous password is valid when new password generated until either one password used or itself expired. Default: true
Generate OTP with customize password
setCustomize($string)
: Random letter from the customize string
Validate OTP with specific attempt times
setAttempts($times)
: The number of incorrect password attempts. Default: 5
Validate OTP with case sensitive
setSensitive($boolean)
: Requiring correct input of uppercase and lowercase letters. Default: true
Generate OTP with seperate password
Sample password
setLength($array)
: The length of the password, use array to separate each length.setSeparator($string)
: The separator of the password. Default: "-"
Validate OTP with extra data
-
setData($var)
: Allows you to get the extra data of OTP. setDisposable($boolean)
: The disposable of the Otp identifier, the different password is not valid when same identifier password used. Default: true
On Success Response
- When you set disposable to
false
, you are able support different password with different extra data for different user in the same identifier key of the OTP.
Validate OTP with skip using
setSkip($boolean)
: Skip using the password when validate, which means you can reuse the password again. Default: false- When there is an error response to the form request, it will skip using the password, but remember to
OTP::validate(...)
in controller.
Delete OTP
- Delete all password with this specific identifier
Delete specific password
Reset attempt times
Demo password
Add the following Key-Value pair to the .env
file in the Laravel application.
- Demo mode for development purposes, no need to use real password to validate.
- Default demo password: "1234", "123456", "12345678"
Contribution
All contributions are welcome! 😄
License
The MIT License (MIT).