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.
By default, a one-time password is a 6-digit number.
You can change the length of the password by setting the password_length parameter in the one-time-passwords config file.
One-time passwords are generated by the Spatie\OneTimePasswords\Support\PasswordGenerators\NumericOneTimePasswordGenerator class.
You can change the password format by creating your own class that extends the Spatie\OneTimePasswords\Support\PasswordGenerator base class.
Here's an example of a custom password generator that generates a 6-character alphanumeric password:
namespace App\Support;
use Spatie\OneTimePasswords\Support\PasswordGenerators\OneTimePasswordGenerator;
class AlphanumericPasswordGenerator implements OneTimePasswordGenerator
{
public function generate(): string
{
return fake()->text($this->numberOfCharacters)
}
}
Then, in your config/one-time-passwords.php file, set the password_generator key to your custom class:
// config/one-time-passwords.php
return [
// ...
'password_generator' => App\Support\AlphanumericPasswordGenerator::class,
];
How can I help you explore Laravel packages today?