ema-salas/otp-generator
最新稳定版本:1.0.0
Composer 安装命令:
composer require ema-salas/otp-generator
包简介
Generate OTP using a Trait into your Laravel models
README 文档
README
Introduction
This is a simple package for Laravel to generate and validate OTPs (One Time Passwords).
Installation 💽
Install via composer
composer require ema-salas/otp-generator
Add service provider to the config/app.php file
<?php /* |-------------------------------------------------------------------------- | Autoloaded Service Providers |-------------------------------------------------------------------------- | | The service providers listed here will be automatically loaded on the | request to your application. Feel free to add your own services to | this array to grant expanded functionality to your applications. | */ 'providers' => [ ... EmaSalas\OtpGenerator\OtpServiceProvider::class, ]; ...
Publish
php artisan vendor:publish
Run Migrations
php artisan migrate
Usage 🧨
NOTE
To use Otp Generator you must use this Trait into your models
<?php use Illuminate\Database\Eloquent\Model; use EmaSalas\OtpGenerator\Otp; class MyModel extends Model { use Otp; }
Generate OTP
<?php $myModel = MyModel::where(['column' => $value])->first(); $token = $myModel->generateToken(string $identifier, int $digits = 4, int $validity = 10)
Validate OTP
<?php $myModel = MyModel::where(['column' => $value])->first(); $myModel::validateOtp(string $token)
$token: The token tied to the identity.
Responses
On Success
{
"status": true,
"message": "OTP is valid"
}
Does not exist
{
"status": false,
"message": "OTP does not exist"
}
Not Valid*
{
"status": false,
"message": "OTP is not valid"
}
Expired
{
"status": false,
"message": "OTP Expired"
}
Inspiration
This package was created inspired in next packages [1]: https://github.com/ichtrojan/laravel-otp/tree/master "ichtrojan/laravel-otp" [2]: https://github.com/erdemkeren/laravel-otp/tree/master "erdemkeren/laravel-otp"
Contribution
If you find an issue with this package or you have any suggestion please help out. I am open to PRs.
统计信息
- 总下载量: 132
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-21