Download the PHP package soiposervices/laravel-otp without Composer
On this page you can find all versions of the php package soiposervices/laravel-otp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download soiposervices/laravel-otp
More information about soiposervices/laravel-otp
Files in soiposervices/laravel-otp
Package laravel-otp
Short Description Laravel OTP generator and validation
License MIT
Homepage https://github.com/SoipoServices/laravel-otp
Informations about the package laravel-otp
Laravel OTP
Introduction
A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache. The cache connection same as your laravel cache config and it supported: "apc", "array", "database", "file", "memcached", "redis"
This is a fork of SoipoServices/laravel-otp , thanks to SoipoServices for his hard work.
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).
If you enjoy this, please consider supporting SoipoServices:
All versions of laravel-otp with dependencies
illuminate/support Version ^5.2|^6.0|^7.0|^8.0|^9.0|^10.0