bonabrian/laravel-otp
Composer 安装命令:
composer require bonabrian/laravel-otp
包简介
Laravel OTP generator and validator without using database
README 文档
README
Installation
Via Composer
composer require bonabrian/laravel-otp
To publish the config file for laravel
php artisan otp:publish
Usage in Laravel
Import the facade class
use Bonabrian\Otp\Facades\Otp;
Generate an OTP:
$code = Otp::generate($secret);
The generated OTP above will only be validated using the same secret within the default expiry time.
TIP: OTP is generally used for verification. So the easiest way of determining the
secretis the user's email/username or phone number or maybe user ID.
Validate an OTP:
$valid = Otp::validate($code, $secret);
Other Generate & Validate options:
// Generate Otp::setDigits(4)->generate($secret); // 4 Digits Otp::setExpiry(30)->generate($secret); // 30 min expiry Otp::setDigits(4)->setExpiry(30)->generate($secret); // 4 Digits, 30 min expiry
Make sure to set the same config during validating. Example:
// Example 1 Otp::validate($code, $secret); // false Otp::setDigits(4)->validate($code, $secret); // true // Example 2 Otp::validate($code, $secret); // false Otp::setExpiry(30)->validate($codde, $secret); // true // Example 3 Otp::validate($code, $secret); // false Otp::setDigits(4)->setExpiry(30)->validate($code, $secret); // true
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-10-20