blackcube/totp
Composer 安装命令:
composer require blackcube/totp
包简介
Totp implementation for PHP
README 文档
README
Installation
If you use Packagist for installing packages, then you can update your composer.json like this :
{
"require": {
"blackcube/totp": "*"
}
}
Testing
To run the tests:
composer install ./vendor/bin/codecept build ./vendor/bin/codecept run
To check coverage report:
./vendor/bin/codecept run --coverage --coverage-html
Usage
Totp class allows you to generate and verify TOTP codes.
Generating TOTP Codes
use blackcube\totp\Totp; $totp = new Totp(); $registerKey = 'JBSWY3DPEHPK3PXP'; // Base 32 encoded Key used to generate the TOTP codes $lostPasswordKey = 'JBSWY3DPEHPK3PXA'; // Base 32 encoded Key used to generate the TOTP codes for lost password service // Define a key for register service $totp->setKey('register', $registerKey); // Define a key for lost password service $totp->setKey('lostPassword', $lostPasswordKey); // we can force the time step (default is 30 seconds) and the window (default is 10) $totp->setWindow(10); // Allow codes to be valid for 10 time steps $totp->setStep(30); // Each time step is 30 seconds // codes are valid for 5 minutes in this case $registerTotpCode = $totp->generate('register'); // Generate a TOTP code for register service $lostPasswordTotpCode = $totp->generate('lostPassword'); // Generate a TOTP code for lost password service
Verifying TOTP Codes
use blackcube\totp\Totp; $totpChcecker = new Totp( step: 30, window: 10 ); $registerKey = 'JBSWY3DPEHPK3PXP'; // Base 32 encoded Key used to generate the TOTP codes $lostPasswordKey = 'JBSWY3DPEHPK3PXA'; // Base 32 encoded Key used to generate the TOTP codes for lost password service // Define a key for register service $totpChcecker->setKey('register', $registerKey); // Define a key for lost password service $totpChcecker->setKey('lostPassword', $lostPasswordKey); // Verify the TOTP code for register service $isRegisterValid = $totp->verify('register', $registerTotpCode); // Verify the TOTP code for lost password service $isLostPasswordValid = $totp->verify('lostPassword', $lostPasswordTotpCode);
Contributing
All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.
Fork the project, create a feature branch , and send us a pull request.
blackcube/totp 适用场景与选型建议
blackcube/totp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「google authenticator」 「totp」 「authy」 「2fa」 「2-factor authentication」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blackcube/totp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blackcube/totp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blackcube/totp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provide a way to secure accesses to all routes of an symfony application.
Basic CAS (SSO) authenticator for Symfony 5.4, 6.0, 7.0 and 8.0
It's a barebone security class written on PHP
Time-based One-time Password implementation for Nette framework
Contao CMS integrity check for some files
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-08-28