PHPackages                             aliirfaan/laravel-simple-otp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. aliirfaan/laravel-simple-otp

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

aliirfaan/laravel-simple-otp
============================

Generate and verify OTP in Laravel for any model type and intent

6.0.1(5mo ago)13.3k↑33.3%MITPHPPHP &gt;=8.0.0CI failing

Since Apr 24Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/aliirfaan/laravel-simple-otp)[ Packagist](https://packagist.org/packages/aliirfaan/laravel-simple-otp)[ RSS](/packages/aliirfaan-laravel-simple-otp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (22)Used By (0)

Laravel Simple OTP
==================

[](#laravel-simple-otp)

This package allows you to generate OTP (One time password). You can then verify the OTP code and grant access based on its validity.

Flexibility
-----------

[](#flexibility)

This package is not tied to Laravel Auth and you can use it to send OTP to any model in your project. For example you can send OTP to a Merchant or Customer model. It does not matter if you are coding a REST API or view based backend, I have tried to code the methods to be used independently.

Features
--------

[](#features)

- Generate random OTP based on length
- Generate random OTP based on type (Numeric, alphanumeric)
- Associate OTP code with a model object using the object id and object type
- Supports OTP per device using device\_id column
- OTP code is hashed for better security
- Validate OTP code based on presence, equality and expiry
- Throws custom exceptions that you can catch and show your custom messages and dispatch your custom events
- Model implements prunable for housekeeping

Requirements
------------

[](#requirements)

- [Composer](https://getcomposer.org/)
- [Laravel](http://laravel.com/)

Installation
------------

[](#installation)

You can install this package on an existing Laravel project with using composer:

```
 $ composer require aliirfaan/laravel-simple-otp
```

Register the ServiceProvider by editing **config/app.php** file and adding to providers array:

```
  aliirfaan\LaravelSimpleOtp\SimpleOtpServiceProvider::class,
```

Note: use the following for Laravel &lt;5.1 versions:

```
 'aliirfaan\LaravelSimpleOtp\SimpleOtpServiceProvider',
```

Publish files with:

```
 $ php artisan vendor:publish --tag=laravel-simple-otp-config"
```

or by using only `php artisan vendor:publish` and select the `aliirfaan\LaravelSimpleOtp\SimpleOtpServiceProvider` from the outputted list.

Apply the migrations:

```
 $ php artisan migrate
```

Configuration
-------------

[](#configuration)

This package publishes an `laravel-simple-otp` file inside your applications's `config` folder which contains the settings for this package. Most of the variables are bound to environment variables, but you are free to directly edit this file, or add the configuration keys to the `.env` file.

```
    'otp_type' => env('OTP_TYPE', 'numeric'),
    'otp_timeout_seconds' => env('OTP_TIMEOUT_SECONDS', 180),
    'otp_length' => env('OTP_LENGTH', 6),
    'otp_should_simulate' => env('OTP_SHOULD_SIMULATE', false),
    'otp_simulated_code' => env('OTP_SIMULATED_CODE'),
    'otp_retention_days' => env('OTP_RETENTION_DAYS', 0),
```

Usage
-----

[](#usage)

```
