spatie/laravel-one-time-passwords
Generate and verify secure one-time passwords (6‑digit by default) in Laravel. Sends OTPs via mail notifications (extendable to SMS/other channels) and includes a Livewire login component. Optional Flux support provides an enhanced OTP input UI.
User model methods, config files). This ensures seamless integration with existing Laravel applications, particularly those using Laravel’s authentication system.OneTimePassword model and createOneTimePassword()/sendOneTimePassword() methods.attemptLoginUsingOneTimePassword()/consumeOneTimePassword() with a ConsumeOneTimePasswordResult enum for state handling.spatie/laravel-one-time-passwords).php artisan vendor:publish --provider="Spatie\OneTimePasswords\OneTimePasswordsServiceProvider").php artisan migrate).one_time_passwords table (simple schema: id, user_id, password, expires_at, ip_address, user_agent).config/one-time-passwords.php).max_attempts in config.session()->regenerate() post-login).use Spatie\OneTimePasswords\HasOneTimePasswords; trait. Add to existing User model.Authenticatable trait and Laravel’s session/auth system.| Stack Component | Compatibility | Notes |
|---|---|---|
| PHP 8.1+ | ✅ Fully supported | |
| Laravel 10/11 | ✅ Official support | Test with your Laravel version. |
| MySQL/PostgreSQL/SQLite | ✅ Database-agnostic (uses Laravel migrations) | |
| Redis | ⚠️ Optional (for caching OTPs) | Requires custom implementation. |
| Livewire | ✅ Optional UI component | No risk if using custom UI. |
| Flux UI | ⚠️ Optional (enhanced OTP input) | No critical dependency. |
| Twilio/Vonage/SMS Gateways | ✅ Extensible via custom notifications | Requires setup for non-email channels. |
| Frontend Frameworks | ✅ Works with any (Livewire/Inertia/React/etc.) | Custom UI can integrate with any frontend. |
composer require spatie/laravel-one-time-passwords
php artisan vendor:publish --provider="Spatie\OneTimePasswords\OneTimePasswordsServiceProvider" --tag="migrations"
php artisan vendor:publish --provider="Spatie\OneTimePasswords\OneTimePasswordsServiceProvider" --tag="config"
php artisan vendor:publish --provider="Spatie\OneTimePasswords\OneTimePasswordsServiceProvider" --tag="views" # Optional
php artisan migrate
config/one-time-passwords.php:
length, expiration_minutes, max_attempts, etc.notification class for custom channels.HasOneTimePasswords trait to User model:
use Spatie\OneTimePasswords\HasOneTimePasswords;
<livewire:one-time-password>
Customize redirect or styling via props/config.$user->sendOneTimePassword(); // Email
How can I help you explore Laravel packages today?