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(2y ago)0448PHP

Since Aug 9Pushed 2y 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 today

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

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

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

[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135224.7k7](/packages/statamic-rad-pack-runway)[jeremy379/laravel-openid-connect

OpenID Connect support to the PHP League's OAuth2 Server. Compatible with Laravel Passport.

59437.0k9](/packages/jeremy379-laravel-openid-connect)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)

PHPackages © 2026

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