spatie/laravel-one-time-passwords

Use one-time passwords (OTP) to authenticate in your Laravel app

0.0.1 2025-05-14 10:17 UTC

This package is auto-updated.

Last update: 2025-05-14 10:38:00 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Using this package, you can securely create and consume one-time passwords. By default, a one-time password is a number of six digits long.

The package provides easy-to-use methods to build the one-time password login flow you want. It also provides a Livewire component to allow users to login using a one-time password.

Here's how you would send a one-time password to a user

// send a mail containing a one-time password

$user->sendOneTimePassword();

Here's how you would try to log in a user using a one-time password.

$user->attemptLoginUsingOneTimePassword($oneTimePassword)

The package tries to make one-time passwords as secure as can be by:

  • letting them expire in a short timeframe (2 minutes by default)
  • only allowing to consume a one-time password on the same IP and user agent as it was generated

All behavior is implemented in action classes that can be modified to your liking.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/laravel-one-time-passwords

You can publish and run the migrations with:

php artisan vendor:publish --tag="laravel-one-time-passwords-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="laravel-one-time-passwords-config"

This is the contents of the published config file:

return [
];

Optionally, you can publish the views using

php artisan vendor:publish --tag="laravel-one-time-passwords-views"

Usage

$laravelOneTimePasswords = new Spatie\LaravelOneTimePasswords();
echo $laravelOneTimePasswords->echoPhrase('Hello, Spatie!');

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.