saeidsharafi/filament-otp-auth
Composer 安装命令:
composer require saeidsharafi/filament-otp-auth
包简介
A Filament plugin for user login using email/phone and OTP verification.
README 文档
README
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
- 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
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
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 theNotifiabletrait. -
email_columnandphone_column: Define the database column names used for email and phone number lookups in your user model (e.g.,'email'and'phone'). Setphone_columntonullif you don't support phone number authentication. -
email_notificationandsms_notification: Specify the notification classes used to send OTP codes via email and SMS. These classes must extendIlluminate\Notifications\Notification. An exampleSendOtpEmailclass is provided with the package. -
otp_length,otp_expiry_minutes, andotp_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 totrueto 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
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.
<?php namespace App\Filament\Pages; use SaeidSharafi\FilamentOtpAuth\Filament\Pages\FilamentOtpAuth as OtpLogin; use Illuminate\Contracts\Support\Htmlable; class OverrideLogin extends OtpLogin { public function getHeading(): string | Htmlable { return 'Example Login Heading'; } }
Then update the config/filament-otp-auth.php with the classname:
'login_page_class' => \App\Filament\Pages\OverrideLogin::class,
Localization
Make sure to publish the translation files and modify them for your desired languages.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
Supported By
saeidsharafi/filament-otp-auth 适用场景与选型建议
saeidsharafi/filament-otp-auth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Authentication」 「email」 「sms」 「login」 「laravel」 「otp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 saeidsharafi/filament-otp-auth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 saeidsharafi/filament-otp-auth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 saeidsharafi/filament-otp-auth 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
Email Toolkit Plugin for CakePHP
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-06