clarity-tech / laravel-otp-generator
一个轻量级的基于缓存存储的 Laravel OTP 生成和验证实现
v1.0.0-rc
2022-07-31 08:50 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
- illuminate/http: ^9.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-08-29 05:50:47 UTC
README
当你使用 Redis 或任何缓存驱动时,它将自动销毁一些东西
这里应该是你的描述。限制为一两段,考虑添加一个小示例。
支持我们
我们投入了大量资源来创建 一流的开放源代码包。您可以通过 购买我们的付费产品之一 来支持我们。
安装
您可以通过 composer 安装此包
composer require clarity-tech/laravel-otp-generator
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="laravel-otp-generator-config"
这是已发布配置文件的内容
// config for ClarityTech/LaravelOtpGenerator return [ 'debug' => false, 'expiry' => env('OTP_EXPIRY', 15 * 60), 'length' => env('OTP_LENGTH', 6), ];
使用方法
use ClarityTech\LaravelOtpGenerator\Facades\AugmentedOTP; $otp = AugmentedOTP::generateWithKey(9706353416); $isValid = AugmentedOTP::withKey(9706353416)->validate(123456); $isValid = AugmentedOTP::withKey(9706353416)->verify(123456);//does not trigger exception
validate 方法会抛出两种异常,根据您的用例处理,并修改响应以向用户输出所需的内容
use ClarityTech\LaravelOtpGenerator\Exceptions\OTPExpiredException; use ClarityTech\LaravelOtpGenerator\Exceptions\OTPInvalidException;
当您有请求上下文可用时,也可以传递它,以便在内部生成更安全的哈希密钥,这将使 OTP 只对会话/ IP 地址有效
$instance = AugmentedOTP::fromRequest(Request $request, string $mobileNo); $otp = $instance->generate(); $otp = $instance->validate(123456);
您可以确定提供的代码是否有效
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全漏洞
请审查 我们的安全策略 了解如何报告安全漏洞。
鸣谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。