PHPackages                             afsakar/filament-otp-login - 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. afsakar/filament-otp-login

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

afsakar/filament-otp-login
==========================

OTP Login for FilamentPHP

v2.0.0(2w ago)6128.6k↓73.2%15MITPHPPHP ^8.2CI passing

Since Mar 24Pushed 2w ago1 watchersCompare

[ Source](https://github.com/afsakar/filament-otp-login)[ Packagist](https://packagist.org/packages/afsakar/filament-otp-login)[ Docs](https://github.com/afsakar/filament-otp-login)[ GitHub Sponsors](https://github.com/afsakar)[ RSS](/packages/afsakar-filament-otp-login/feed)WikiDiscussions v2 Synced 3d ago

READMEChangelog (10)Dependencies (26)Versions (19)Used By (0)

OTP Login for FilamentPHP
=========================

[](#otp-login-for-filamentphp)

[![Latest Version on Packagist](https://camo.githubusercontent.com/71625befaf94430a84ba5ab3d075bd3ca68d97d88207a08debcdf370b8555758/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616673616b61722f66696c616d656e742d6f74702d6c6f67696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/afsakar/filament-otp-login)[![Total Downloads](https://camo.githubusercontent.com/bad2a4a13d86dfbbef8f725374b6819c2643d207b74236b660c7960b2ddfca02/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616673616b61722f66696c616d656e742d6f74702d6c6f67696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/afsakar/filament-otp-login)

 [![OTP Login for FilamentPHP](https://raw.githubusercontent.com/afsakar/filament-otp-login/refs/heads/v2/assets/afsakar-otp-login.png)](https://raw.githubusercontent.com/afsakar/filament-otp-login/refs/heads/v2/assets/afsakar-otp-login.png)

This package is an OTP Login for FilamentPHP. It is a simple package that allows you to login to your FilamentPHP application using OTP.

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

[](#installation)

You can install the package via composer:

```
composer require afsakar/filament-otp-login
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="filament-otp-login-migrations"
php artisan migrate
```

You can publish the translations files with:

```
php artisan vendor:publish --tag="filament-otp-login-translations"
```

Optionally, you can publish the views using

```
php artisan vendor:publish --tag="filament-otp-login-views"
```

Upgrade Guide
-------------

[](#upgrade-guide)

This release targets Filament `^4.0 || ^5.0` and PHP `^8.2`. Filament v2/v3 projects must upgrade Filament before upgrading this package.

Configuration moved from the config file to `FilamentOtpLoginPlugin`, so define settings per panel:

```
FilamentOtpLoginPlugin::make()
    ->otpCode(length: 6, expiresIn: 120)
    ->rateLimit(attempts: 5, decaySeconds: 60)
    ->resendLimit(attempts: 3, decaySeconds: 300)
    ->passwordless(false)
    ->notification(\Afsakar\FilamentOtpLogin\Notifications\SendOtpCode::class);
```

The published config file is intentionally empty.

If you published the login views, publish them again or update them for Filament v4/v5 components and translation namespaces. The package now uses Filament's native `OneTimeCodeInput`, so remove any custom references to `Afsakar\FilamentOtpLogin\Filament\Forms\OtpInput`.

The OTP table column changed from `email` to `identifier`. Publish and run the new migration, or add this to your own upgrade migration:

```
Schema::table('otp_codes', function (Blueprint $table) {
    $table->renameColumn('email', 'identifier');
});
```

OTP codes are now stored as hashes. Any active OTP code created before the upgrade will no longer verify; users can request a new code.

Usage
-----

[](#usage)

Just register the `Afsakar\FilamentOtpLogin\FilamentOtpLoginPlugin` plugin in the your panel provider file.

```
use Afsakar\FilamentOtpLogin\FilamentOtpLoginPlugin;

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                FilamentOtpLoginPlugin::make()
                    ->otpCode(length: 6, expiresIn: 120)
                    ->rateLimit(attempts: 5, decaySeconds: 60)
                    ->resendLimit(attempts: 3, decaySeconds: 300),
            ]);
    }
```

For phone based login:

```
FilamentOtpLoginPlugin::make()
    ->identifierFormField('phone', label: 'Phone', type: 'tel')
    ->userIdentifierColumn('phone');
```

Use `->tableName()`, `->identifierColumn()`, `->userModel()`, `->passwordless()`, and `->notification()` when a panel needs different behavior.

If you want to ignore specific user groups from OTP login just implement the `Afsakar\FilamentOtpLogin\Models\Contracts\CanLoginDirectly` trait in your User model.

```
use Afsakar\FilamentOtpLogin\Models\Contracts\CanLoginDirectly;

class User extends Authenticatable implements CanLoginDirectly
{
    use HasFactory, Notifiable;

    // other user model code

    public function canLoginDirectly(): bool
    {
        return str($this->email)->endsWith('@example.com');
    }
}
```

**Note:* For medium and large scale applications, you only need to run "php artisan model:prune" command as cron to prevent the otp\_code table from bloating and performance issues.*

OTP codes are hashed before they are stored in the database.

To enable passwordless login, call `->passwordless()`. When enabled, users log in with the configured identifier and OTP only.

Custom Login Page
-----------------

[](#custom-login-page)

If you want to customize the login page, you can extend the `\Afsakar\FilamentOtpLogin\Filament\Pages\Login` page and set your custom login page to plugin in the panel provider file with `loginPage` method.

```
