jp3cki/totp

RFC 6238 / TOTP: 基于时间的单次密码算法

v3.0.0 2024-06-24 03:22 UTC

This package is auto-updated.

Last update: 2024-09-24 03:54:26 UTC


README

PHP实现RFC6238(TOTP:基于时间的单次密码算法)。

License Latest Stable Version CI

需求

  • PHP(64位):PHP 8.1或更高版本
  • PHP扩展:hash

安装

  1. 设置Composer,事实上的标准包管理器。
  2. 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);

许可

MIT许可.

版权(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()