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

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

osenco/filament-otp-login
=========================

OTP Login for FilamentPHP

1.0(4mo ago)01MITPHPPHP ^8.1

Since Dec 17Pushed 4mo agoCompare

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

READMEChangelog (1)Dependencies (13)Versions (2)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)

[![Screenshot](https://camo.githubusercontent.com/290506eff1445bf2af57ba3f5f4b2837a2456c5070c347287c3119c362ccd81a/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f46696c616d656e742532304f54502532304c6f67696e2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d616673616b617225324666696c616d656e742d6f74702d6c6f67696e267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d53696d706c652b4f54502b4c6f67696e2b666f722b46696c616d656e74504850266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d6c6f67696e)](https://camo.githubusercontent.com/290506eff1445bf2af57ba3f5f4b2837a2456c5070c347287c3119c362ccd81a/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f46696c616d656e742532304f54502532304c6f67696e2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d616673616b617225324666696c616d656e742d6f74702d6c6f67696e267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d53696d706c652b4f54502b4c6f67696e2b666f722b46696c616d656e74504850266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d6c6f67696e)

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 config and translations files with:

```
php artisan vendor:publish --tag="filament-otp-login-config"
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"
```

This is the contents of the published config file:

```
return [
    'table_name' => 'otp_codes', // Table name to store OTP codes

    'otp_code' => [
        'length' => env('OTP_LOGIN_CODE_LENGTH', 6), // Length of the OTP code
        'expires' => env('OTP_LOGIN_CODE_EXPIRES_SECONDS', 120), // Expiration time of the OTP code in seconds
    ],

    'notification_class' => \Afsakar\FilamentOtpLogin\Notifications\SendOtpCode::class,
];
```

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(),
            ]);
    }
```

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

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.

```
