PHPackages                             murkrow/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. murkrow/simple-otp

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

murkrow/simple-otp
==================

1.0.8(1y ago)0388PHP

Since Aug 9Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (10)Used By (0)

Simple OTP
==========

[](#simple-otp)

This package provides a simple way to manage One-Time Passwords (OTPs) for your application users. This package includes functionality for generating, validating, and managing OTPs associated with your user models in a Laravel application.

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

[](#installation)

To install the Simple OTP package, run the following command:

```
composer require murkrow/simple-otp
```

### Running migrations

[](#running-migrations)

Remember to run the migrations to create the `otps` table.

```
php artisan migrate
```

### (Optional) Publishing vendor files

[](#optional-publishing-vendor-files)

You can publish the config file and the migration using

```
php artisan vendor:publish
```

Usage
-----

[](#usage)

### Adding the Trait to Your User Model

[](#adding-the-trait-to-your-user-model)

To enable OTP functionality for your user model, add the `HasOtps` trait to the model. Typically, this will be your `User` model.

```
namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Murkrow\Otp\Traits\HasOtps;

class User extends Authenticatable
{
    use HasOtps;

    // Your user model code here
}
```

### Generating an OTP

[](#generating-an-otp)

To generate an OTP, use the `OtpBuilder` class. You can customize the OTP length, whether it is alphanumeric, its expiration time, and associate it with a user.

```
use Murkrow\Otp\Builders\OtpBuilder;

$otp = (new OtpBuilder())
    ->forUser($user) // User object
    ->length(6) // Length of the OTP
    ->alphaNumeric(true) // Alphanumeric or numeric
    ->tag('login') // Optional tag
    ->expiresInMinutes(30) // Expiration time in minutes
    ->create();
```

### Validating an OTP

[](#validating-an-otp)

To validate an OTP, use the `validateOtp` method provided by the `HasOtps` trait:

```
$user = User::find(1); // User object

$isValid = $user->validateOtp($otp, 'login'); // OTP and optional tag

if ($isValid) {
    // OTP is valid
} else {
    // OTP is invalid
}
```

### Validating and Removing an OTP

[](#validating-and-removing-an-otp)

To validate and remove an OTP after successful validation, use the `validateAndRemoveOtp` method:

```
$isValid = $user->validateAndRemoveOtp($otp, 'login'); // OTP and optional tag

if ($isValid) {
    // OTP is valid and removed
} else {
    // OTP is invalid
}
```

Example
-------

[](#example)

Here is an example of how to generate an OTP for a user, validate it, and then remove it after successful validation:

```
use App\Models\User;
use Murkrow\Otp\Builders\OtpBuilder;

// Assume $user is an instance of the User model
$user = User::find(1);

// Generate an OTP
$otpBuilder = new OtpBuilder();
$otp = $otpBuilder
    ->forUser($user)
    ->length(6)
    ->alphaNumeric(true)
    ->expiresInMinutes(30)
    ->create();

// Validate the OTP
$isValid = $user->validateOtp($otp->code, 'login');

if ($isValid) {
    echo "OTP is valid!";
} else {
    echo "Invalid OTP!";
}

// Validate and remove the OTP
$isValidAndRemoved = $user->validateAndRemoveOtp($otp->code, 'login');

if ($isValidAndRemoved) {
    echo "OTP is valid and has been removed!";
} else {
    echo "Invalid OTP!";
}
```

### Configuration

[](#configuration)

#### Maximum Number of OTPs Per User

[](#maximum-number-of-otps-per-user)

By default, a user can have up to 5 OTPs at a time. If a user exceeds this limit, the oldest OTP will be deleted. You can change this behavior by setting the `max_otps_per_user` configuration value in the `otp` configuration file.

```
// config/otp.php
max_otps_per_user' => 5,
```

License
-------

[](#license)

This package is open-sourced software licensed under the [GNU General Public License v3.0](LICENSE).

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~36 days

Recently: every ~3 days

Total

9

Last Release

720d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b1466e76ca952c12721cc4358e28d82c25402f810954e0001acbf4cd38be3af?d=identicon)[murkrow](/maintainers/murkrow)

---

Top Contributors

[![Murkrow02](https://avatars.githubusercontent.com/u/38087157?v=4)](https://github.com/Murkrow02 "Murkrow02 (16 commits)")

### Embed Badge

![Health badge](/badges/murkrow-simple-otp/health.svg)

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

###  Alternatives

[lab404/laravel-impersonate

Laravel Impersonate is a plugin that allows to you to authenticate as your users.

2.3k16.4M48](/packages/lab404-laravel-impersonate)[santigarcor/laratrust

This package provides a flexible way to add Role-based Permissions to Laravel

2.3k5.4M43](/packages/santigarcor-laratrust)[overtrue/laravel-follow

User follow unfollow system for Laravel.

1.2k404.7k5](/packages/overtrue-laravel-follow)[codegreencreative/laravel-samlidp

Make your PHP Laravel application an Identification Provider using SAML 2.0. This package allows you to implement your own Identification Provider (idP) using the SAML 2.0 standard to be used with supporting SAML 2.0 Service Providers (SP).

263763.5k1](/packages/codegreencreative-laravel-samlidp)

PHPackages © 2026

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