PHPackages                             soiposervices/laravel-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. soiposervices/laravel-otp

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

soiposervices/laravel-otp
=========================

Laravel OTP generator and validation

0.0.1(3y ago)024MITPHPPHP ^5.5.9|^7.0|^8.0|^8.1|^8.2

Since Mar 30Pushed 5mo agoCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (0)

Laravel OTP
===========

[](#laravel-otp)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5828864d7501acbe615e74166696e86dfc50747da508494b181dc83d476bcf1c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f536f69706f53657276696365732f6c61726176656c2d6f74702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/SoipoServices/laravel-otp)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/SoipoServices/laravel-otp)[![Total Downloads](https://camo.githubusercontent.com/90d0d060b3b25e008700d14faaa491c4e5221bd22a557e909b8028ef54b4a7a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f536f69706f53657276696365732f6c61726176656c2d6f74702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/SoipoServices/laravel-otp)

Introduction
------------

[](#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
------------

[](#installation)

### Install via composer

[](#install-via-composer)

```
composer require soiposervices/laravel-otp
```

### Add Service Provider &amp; Facade

[](#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`:

```
SoipoServices\Otp\OtpServiceProvider::class
```

Add the Facade to the aliases array in `config/app.php`:

```
'Otp' => SoipoServices\Otp\OtpFacade::class
```

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

[](#configuration)

Publish config and language file

```
php artisan vendor:publish --provider="SoipoServices\Otp\OtpServiceProvider"
```

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.

```
OTP_FORMAT=numeric
OTP_LENGTH=6
OTP_SENSITIVE=false
OTP_EXPIRES_TIME=15
OTP_ATTEMPT_TIMES=5
OTP_REPEATED=true
OTP_DEMO=false

```

Usage
-----

[](#usage)

### Generate OTP

[](#generate-otp)

```
Otp::generate(string $identifier)
```

- `$identifier`: The identity that will be tied to the OTP.

#### Sample

[](#sample)

```
use OTP;

// in controller

$password = Otp::generate('reg:name@domain.com');
```

This will generate a OTP that will be valid for 15 minutes.

### Validate OTP

[](#validate-otp)

```
Otp::validate(string $identifier, string $password)
```

- `$identifier`: The identity that is tied to the OTP.
- `$password`: The password tied to the identity.

#### Sample

[](#sample-1)

```
use OTP;

// in controller

$result = Otp::validate('reg:name@domain.com', '123456');
```

#### Responses

[](#responses)

**On Success**

```
{
  "status": true
}

```

**Invalid OTP**

```
{
  "status": false,
  "error": "invalid"
}

```

**Expired**

```
{
  "status": false,
  "error": "expired"
}

```

**Max attempt**

```
{
  "status": false,
  "error": "max_attempt"
}

```

- Reached the maximum allowed attempts, default 10 times with each identifier

### Validate OTP by Laravel Validation

[](#validate-otp-by-laravel-validation)

```
// in a `FormRequest`

use SoipoServices\Otp\Rules\OtpValidate;

public function rules()
{
    return [
        'code' => ['required', new OtpValidate('change-email:name@domain.com')]
    ];
}

// in a controller

$request->validate([
    'code' => ['required', new OtpValidate('change-email:name@domain.com')]
]);
```

### Validate OTP by session id

[](#validate-otp-by-session-id)

```
// Otp class

$result = Otp::validate('123456');

// in a `FormRequest`

use SoipoServices\Otp\Rules\OtpValidate;

public function rules()
{
    return [
        'code' => ['required', new OtpValidate()]
    ];
}

// in a controller

$request->validate([
    'code' => ['required', new OtpValidate()]
]);
```

- 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
--------------

[](#advanced-usage)

### Generate OTP with options

[](#generate-otp-with-options)

```
$password = Otp::setLength(8)->setFormat('string')->setExpires(60)->setRepeated(false)->generate('identifier-key-here');

// or array option

$password = Otp::generate('identifier-key-here', [
    'length' => 8,
    'format' => 'string',
    'expires' => 60,
    'repeated' => false
]);
```

- `setLength($length)`: The length of the password. Default: 6
- `setFormat($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: 15
- `setRepeated($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

[](#generate-otp-with-customize-password)

```
$password = Otp::setCustomize('12345678ABC@#$')->generate('identifier-key-here');
```

- `setCustomize($string)`: Random letter from the customize string

### Validate OTP with specific attempt times

[](#validate-otp-with-specific-attempt-times)

```
$password = Otp::setAttempts(3)->validate('identifier-key-here', 'password-here');
```

- `setAttempts($times)`: The number of incorrect password attempts. Default: 5

### Validate OTP with case sensitive

[](#validate-otp-with-case-sensitive)

```
$password = Otp::setSensitive(true)->generate('identifier-key-here');

// validate

$result = Otp::setSensitive(true)->validate('identifier-key-here', 'password-here');

// in controller

use SoipoServices\Otp\Rules\OtpValidate;

$request->validate([
    'code' => ['required', new OtpValidate('identifier-key-here', ['sensitive' => true])]
]);
```

- `setSensitive($boolean)`: Requiring correct input of uppercase and lowercase letters. Default: true

### Generate OTP with seperate password

[](#generate-otp-with-seperate-password)

```
$password = Otp::setLength([4,3,4])->setSeparator(':')->generate('identifier-key-here');
```

**Sample password**

```
3526:126:3697

```

- `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

[](#validate-otp-with-extra-data)

```
$password = Otp::setData(['user_id' => auth()->id()])->generate('login-confirmation');
```

- `setData($var)`: Allows you to get the extra data of OTP.

```
// validate

$result = Otp::setDisposable(false)->validate('login-confirmation', 'password-here');

// in controller

use SoipoServices\Otp\Rules\OtpValidate;

$request->validate([
    'code' => ['required', new OtpValidate('login-confirmation', ['disposable' => false])]
]);
```

- `setDisposable($boolean)`: The disposable of the Otp identifier, the different password is not valid when same identifier password used. Default: true

**On Success Response**

```
{
  "status": true,
  "data": [
    "user_id": 10
  ]
}

```

- 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

[](#validate-otp-with-skip-using)

```
// validate

$result = Otp::setSkip(true)->validate('identifier-key-here', 'password-here');

// in controller

use SoipoServices\Otp\Rules\OtpValidate;

$request->validate([
    'code' => ['required', new OtpValidate('identifier-key-here', ['skip' => true])]
]);
```

- `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-otp)

```
Otp::forget('identifier-key-here');
```

- Delete all password with this specific identifier

### Delete specific password

[](#delete-specific-password)

```
Otp::forget('identifier-key-here', 'password-here');
```

### Reset attempt times

[](#reset-attempt-times)

```
Otp::resetAttempt('identifier-key-here');
```

### Demo password

[](#demo-password)

Add the following Key-Value pair to the `.env` file in the Laravel application.

```
OTP_DEMO=true

```

- Demo mode for development purposes, no need to use real password to validate.
- Default demo password: "1234", "123456", "12345678"

Contribution
------------

[](#contribution)

All contributions are welcome! 😄

License
-------

[](#license)

The MIT License (MIT).

If you enjoy this, please consider supporting SoipoServices:

[![Buy Me A Coffee](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67)](https://www.buymeacoffee.com/SoipoServices)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance48

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1139d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cbf7b15aa95b4f96a243793fdcb6365420dda7a873cef7424384ea815aa80bf?d=identicon)[SoipoServices](/maintainers/SoipoServices)

---

Top Contributors

[![teckwei1993](https://avatars.githubusercontent.com/u/7748272?v=4)](https://github.com/teckwei1993 "teckwei1993 (28 commits)")[![soipo](https://avatars.githubusercontent.com/u/2483887?v=4)](https://github.com/soipo "soipo (3 commits)")

---

Tags

laravelotpemail validationone time passwordsone time pinmobile validation

### Embed Badge

![Health badge](/badges/soiposervices-laravel-otp/health.svg)

```
[![Health](https://phpackages.com/badges/soiposervices-laravel-otp/health.svg)](https://phpackages.com/packages/soiposervices-laravel-otp)
```

###  Alternatives

[teckwei1993/laravel-otp

Laravel OTP generator and validation

5556.0k](/packages/teckwei1993-laravel-otp)[erdemkeren/laravel-otp

Secure your laravel routes with otps. (one time passwords)

1608.5k](/packages/erdemkeren-laravel-otp)[fouladgar/laravel-otp

This package provides convenient methods for sending and validating OTP notifications to users for authentication.

21426.5k](/packages/fouladgar-laravel-otp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
