saddamsegwitz / otp-generator
Laravel 应用程序的 OTP 生成器和验证器
1.0.0
2022-03-23 07:30 UTC
Requires
- php: ^7.3|7.4|^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3
- vimeo/psalm: ^3.11|^4.3
This package is auto-updated.
Last update: 2024-09-23 13:42:09 UTC
README
安装
您可以通过 composer 安装此包
composer require Segwitz/otp-generator
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --provider="Segwitz\Otp\OtpServiceProvider" --tag="migrations" php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Segwitz\Otp\OtpServiceProvider" --tag="config"
使用方法
use Segwitz\Otp\Otp; . . $otp = Otp::generate($identifier); . $verify = Otp::validate($identifier, $otp->token); // example response { "status": true "message": "OTP is valid" } // to get an expiredAt time $expires = Otp::expiredAt($identifier); // example response { +"status": true +"expired_at": Illuminate\Support\Carbon @1611895244^ { .... #dumpLocale: null date: 2021-01-29 04:40:44.0 UTC (+00:00) }
您可以在 otp-generator.php 配置文件中更新设置,同时在生成时也可以控制
高级使用
use Segwitz\Otp\Otp; . . $otp = Otp::setValidity(30) // otp validity time in mins ->setLength(4) // Lenght of the generated otp ->setMaximumOtpsAllowed(10) // Number of times allowed to regenerate otps ->setOnlyDigits(false) // generated otp contains mixed characters ex:ad2312 ->setUseSameToken(true) // if you re-generate OTP, you will get same token ->generate($identifier); . $verify = Otp::setAllowedAttempts(10) // number of times they can allow to attempt with wrong token ->validate($identifier, $otp->token);
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
致谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。