Download the PHP package mydaniel/laravel-temporary-tokens without Composer
On this page you can find all versions of the php package mydaniel/laravel-temporary-tokens. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-temporary-tokens
Laravel Temporary Tokens
A simple and flexible Laravel package that allows you to generate, manage, and validate temporary tokens, One-Time Passwords (OTPs), or PINs for tasks like authentication, email verification, password resets, and more.
Features
- Generate numeric tokens of any length.
- Set expiration dates for tokens.
- Limit the number of times a token can be used.
- Attach arbitrary data (metadata) to any token.
- Associate tokens with any Eloquent model (e.g.,
User
). - Includes an Artisan command to automatically prune expired tokens.
- Fully configurable with no external dependencies.
Installation
You can install the package via Composer:
Next, you should publish the configuration and migration files using the vendor:publish
command:
Finally, run the migration to create the temporary_tokens
table:
Usage
1. Preparing Your Model
First, add the HasTemporaryTokens
trait to the model you wish to generate tokens for (e.g., your User
model).
2. Creating a Token
You can easily create new tokens using the fluent TokenBuilder
.
Create a simple 6-digit token for a user:
Create a token with custom settings:
3. Finding and Validating a Token
To find and check the validity of a token, you can use the methods on the TemporaryToken
model.
The isValid()
method is also available on a TemporaryToken
instance to perform the same check:
4. Using a Token
After a token has been successfully used, you can increment its usage counter.
Pruning Expired Tokens
You can remove expired tokens from your database by running the provided Artisan command.
By default, this command will prune tokens that expired more than 24 hours ago. To customize this, you can either use the --hours
option or change the prune_expired_after_hours
value in the config/temporary-tokens.php
file.
It is recommended to schedule this command to run daily in your app/Console/Kernel.php
file.
Changelog
Please see CHANGELOG.md for more information on what has changed recently.
Contributing
Contributions are welcome! Please feel free to fork the repository and submit a pull request.
Security Vulnerabilities
If you discover a security vulnerability within this package, please send an e-mail to Daniel Yousefi Far at [email protected]
. All security vulnerabilities will be promptly addressed.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-temporary-tokens with dependencies
illuminate/contracts Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0