Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wotzebra/laravel-verification-code
Authenticate users using a verification code sent to their mail.
https://github.com/wotzebra/laravel-verification-code
authentication laravel php verification
Last synced: 6 days ago
JSON representation
Authenticate users using a verification code sent to their mail.
- Host: GitHub
- URL: https://github.com/wotzebra/laravel-verification-code
- Owner: wotzebra
- License: mit
- Created: 2020-02-03T09:11:03.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-26T11:08:59.000Z (4 months ago)
- Last Synced: 2025-01-03T19:12:27.364Z (13 days ago)
- Topics: authentication, laravel, php, verification
- Language: PHP
- Homepage:
- Size: 139 KB
- Stars: 61
- Watchers: 6
- Forks: 18
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Verification Code
[![Latest Version on Packagist](https://img.shields.io/packagist/v/wotz/laravel-verification-code.svg?style=flat-square)](https://packagist.org/packages/wotz/laravel-verification-code)
[![Total Downloads](https://img.shields.io/packagist/dt/wotz/laravel-verification-code.svg?style=flat-square)](https://packagist.org/packages/wotz/laravel-verification-code)This package makes it possible to authenticate a user via a verification code.
## Installation
You can install this package using composer:
```bash
composer require wotz/laravel-verification-code
```The package will automatically register itself.
You can publish the migration with:
```bash
php artisan vendor:publish --provider="Wotz\VerificationCode\VerificationCodeServiceProvider" --tag="migrations"
```After publishing the migration, run the migration with:
```bash
php artisan migrate
```You can publish the config file with:
```bash
php artisan vendor:publish --provider="Wotz\VerificationCode\VerificationCodeServiceProvider" --tag="config"
```## Usage
### Generate and send a verification code
```php
use Wotz\VerificationCode\VerificationCode;VerificationCode::send($email);
```
This will generate a verification code for the user. The code will be stored in the `verification_codes` table. An email with the generated code will then be sent to the user matching the given email address.### Verify a verification code
```php
use Wotz\VerificationCode\VerificationCode;VerificationCode::verify($code, $email);
```
If the verification code is expired or does not match the user's email address, it will return `false`. If valid, it will return `true` and delete the code.If you do not want the code to be deleted (in case the same code needs to be verified at different points in the login flow) you can pass a third parameter.
```php
use Wotz\VerificationCode\VerificationCode;VerificationCode::verify($code, $email, $deleteAfterVerification);
```### Verification codes table cleanup
Since it is possible for the verification codes table to fill up with unused codes, the following command will prune all codes older than the given hours.
```php
php artisan verification-code:prune --hours=24
```## Config settings
### Length
This value defines the length of every generated verification code.### Characters
You can define which characters are used to generate a verification code. By default, certain characters are excluded (0, O, I, L) because they look too similar.### Expire seconds
A verification code is only valid for a certain amount of time. You can define after how many seconds a verification code will expire.### Max codes per verifiable
By default, only one verification code can be active per verifiable. If you want to allow multiple active codes per verifiable, then you can
change this setting to a different number (or to `null` if you want unlimited codes per verifiable).### Custom Notification
If you want to use a custom notification to send the verification code, you can create your own notification class which should extend the `VerificationCodeCreatedInterface`. Make sure you don't forget to pass the verification code to the mail.### Custom Model
If you want to use a custom verification code model, you can create your own verification code class which should extend the `VerificationCode`.### Queue
If your notification is queueable, you can define the queue that will be used for the notification.### Test verifiables and test code
You sometimes may want to allow a user to log in immediately without letting them go through the verification code flow. To do this you can add the verifiable (e.g. email address) to the `test_verifiables` array. You then need to define a `test_code`. The combination of the verifiable and the test code will make it possible for the user to pass through.## Testing
You can run tests with:
``` bash
composer test
```
## Linting```bash
composer lint
```
## ChangelogPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Credits
- [Günther Debrauwer](https://github.com/gdebrauwer)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.