jp3cki / totp
RFC 6238 / TOTP: 基于时间的单次密码算法
v3.0.0
2024-06-24 03:22 UTC
Requires
- php: >= 8.1
- php-64bit: >= 8.1
- ext-hash: *
- christian-riesen/base32: ^1.6
Requires (Dev)
- ergebnis/composer-normalize: ^2.43
- jp3cki/coding-standard: ^1.0.0
- phpstan/phpstan: ^1.11.5
- phpunit/phpunit: ^10.5.24
- squizlabs/php_codesniffer: ^3.10.1
This package is auto-updated.
Last update: 2024-09-24 03:54:26 UTC
README
PHP实现RFC6238(TOTP:基于时间的单次密码算法)。
需求
- PHP(64位):PHP 8.1或更高版本
- PHP扩展:hash
安装
- 设置Composer,事实上的标准包管理器。
php composer.phar require jp3cki/totp
用法
<?php declare(strict_types=1); use jp3cki\totp\Totp; require_once('vendor/autoload.php'); // Generate new shared-secret key (for each user) $secret = Totp::generateKey(); echo "secret: {$secret}\n"; echo "\n"; // Make URI for importing from QRCode. $uri = Totp::createKeyUriForGoogleAuthenticator($secret, 'theuser@example.com', 'Issuer Name'); echo "uri: {$uri}\n"; echo "\n"; // Verify user input $userInput = '123456'; // $_POST['totp'] $isValid = Totp::verify($userInput, $secret, time()); var_dump($isValid);
许可
版权(c)2015-2024 AIZAWA Hina <hina@fetus.jp>
贡献
欢迎补丁和/或报告问题。
- 请为每个问题或功能创建新分支。(master分支不应该工作)
- 请编写并运行测试。
$ make test
- 请运行check-style进行静态代码分析和编码规则检查。
$ make check-style
- 请清理提交。
- 请为每个问题或功能创建新的pull-request。
- 请使用日语或非常简单的英语创建新的pull-request或问题。
破坏性变更
-
v3.0.0
- 最低环境现在是PHP 8.1
-
v2.0.0
- 最低环境现在是PHP 7.2
- 现在强制执行参数类型
- 移除了
Random::generate*()
。现在始终使用random_bytes()
。