PHPackages                             saeidsharafi/filament-otp-auth - 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. saeidsharafi/filament-otp-auth

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

saeidsharafi/filament-otp-auth
==============================

A Filament plugin for user login using email/phone and OTP verification.

v1.0.0(1y ago)118MITPHPPHP ^8.1CI failing

Since Apr 6Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (12)Versions (2)Used By (0)

Filament OTP Authentication
===========================

[](#filament-otp-authentication)

[![Latest Version on Packagist](https://camo.githubusercontent.com/25009d06222d772d1a75c910c1449388929fd7b374c7d4a91a9695ef894a4c46/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7361656964736861726166692f66696c616d656e742d6f74702d617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/saeidsharafi/filament-otp-auth)[![Total Downloads](https://camo.githubusercontent.com/e8d60f8f54f3acbcb42e62bd7957f6b8699c56ad503b14fea7fb6335269981a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7361656964736861726166692f66696c616d656e742d6f74702d617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/saeidsharafi/filament-otp-auth)

[![Screenshot](https://camo.githubusercontent.com/182efcaafd07ce6f32131e6209cbcd4a34e1e8c75b5b45a2a0b79342daf70baa/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f46696c616d656e742532304f545025323041757468656e7469636174696f6e2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d73616569647368617261666925324666696c616d656e742d6f74702d61757468267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d41757468656e7469636174652b776974682b4f54502b7669612b456d61696c2b6f722b50686f6e652b666f722b46696c616d656e74504850266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d656d61696c)](https://camo.githubusercontent.com/182efcaafd07ce6f32131e6209cbcd4a34e1e8c75b5b45a2a0b79342daf70baa/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f46696c616d656e742532304f545025323041757468656e7469636174696f6e2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d73616569647368617261666925324666696c616d656e742d6f74702d61757468267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d41757468656e7469636174652b776974682b4f54502b7669612b456d61696c2b6f722b50686f6e652b666f722b46696c616d656e74504850266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d656d61696c)

This package provides a flexible OTP (One-Time Password) authentication solution for FilamentPHP. It allows users to log in using either their email or phone number, and receive an OTP code for verification. Users that have already set a password can use that for normal username/password authentication. This also provides an OTP-based forgot password flow.

Key Features
------------

[](#key-features)

- **Email or Phone Authentication:** Supports login via email or phone number.
- **OTP Verification:** Replaces traditional passwords with secure OTP codes.
- **Password Support:** Users with stored passwords can still log in via username/password.
- **Forgot Password Flow:** Allows users to reset their passwords using OTP verification.
- **Customizable:** Offers extensive configuration options, including OTP length, expiry, and notification methods.
- **Rate Limiting:** Protects against brute-force attacks with configurable rate limiting.
- **User Creation:** Optionally creates new users if they don't exist in the database.
- **Filament Integration:** Seamlessly integrates into your FilamentPHP admin panel.
- **Customizable Login Page:** Override the default login page for a tailored user experience.

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

[](#installation)

You can install the package via composer:

```
composer require saeidsharafi/filament-otp-auth
```

Publish the configuration file:

```
php artisan vendor:publish --tag="filament-otp-auth-config"
```

Publish and run the migrations:

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

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

[](#configuration)

After publishing the configuration file (`config/filament-otp-auth.php`), you can customize the package's behavior. Here are some of the most important configuration options:

- **`authenticatable`**: Specifies the Eloquent model representing your users (e.g., `App\Models\User::class`). Ensure this model uses the `Notifiable` trait.
- **`email_column` and `phone_column`**: Define the database column names used for email and phone number lookups in your user model (e.g., `'email'` and `'phone'`). Set `phone_column` to `null` if you don't support phone number authentication.
- **`email_notification` and `sms_notification`**: Specify the notification classes used to send OTP codes via email and SMS. These classes must extend `Illuminate\Notifications\Notification`. An example `SendOtpEmail` class is provided with the package.
- **`otp_length`**, **`otp_expiry_minutes`**, and **`otp_resend_delay_seconds`**: Configure the OTP's length, validity duration (in minutes), and the minimum time (in seconds) a user must wait before requesting a new OTP.
- **`create_user_if_not_exists`**: Set to `true` to automatically create a new user if the provided email or phone number doesn't exist in the database. Ensure your User model's fillable property includes the identifier column(s).
- **`login_page_class`**: Allows you to specify a custom Filament page class for the login screen. This allows for extensive customization of the login experience. The default is `\SaeidSharafi\FilamentOtpAuth\Filament\Pages\FilamentOtpAuth::class`.

Usage
-----

[](#usage)

No plugin registration is required, since the Filament page is registered directly in the config file.

**1. Configure Your User Model:**

Ensure your `User` model (or the model specified in `authenticatable`) uses the `Notifiable` trait and has the `email` and `phone` (if you are using phone authentication) columns fillable.

**2. Define Notification Classes:**

Create notification classes (e.g., `SendOtpEmail`) that extend `Illuminate\Notifications\Notification` and handle sending the OTP code via email and/or SMS. The example `SendOtpEmail` class is provided with the package.

**3. (Optional) Customize the Login Page:**

If you want to customize the login page, you can extend the `\SaeidSharafi\FilamentOtpAuth\Filament\Pages\FilamentOtpAuth` page and set your custom login page to plugin in the `login_page_class` setting in the config file.

```
