christian-riesen/otp
Composer 安装命令:
composer require christian-riesen/otp
包简介
One Time Passwords, hotp and totp according to RFC4226 and RFC6238
README 文档
README
Did you like this? Flattr it:
Installation
Use composer and require the library in your composer.json
{
"require": {
"christian-riesen/otp": "^2.0",
}
}
Usage
<?php use Otp\Otp; use Otp\GoogleAuthenticator; use ParagonIE\ConstantTime\Encoding; // Get a Pseudo Secret // Defaults to 16 characters $secret = GoogleAuthenticator::generateRandom(); // Url for the QR code // Using totp method $url = GoogleAuthenticator::getQrCodeUrl('totp', 'Label like user@host.com', $secret); // Save the secret with the users account // Display QR Code to the user // Now how to check $otp = new Otp(); // $key is a 6 digit number, coming from the User // Assuming this is present and sanitized // Allows for a 1 code time drift by default // Third parameter can alter that behavior if ($otp->checkTotp(Encoding::base32DecodeUpper($secret), $key)) { // Correct key // IMPORTANT! Note this key as being used // so nobody could launch a replay attack. // Cache that for the next minutes and you // should be good. } else { // Wrong key } // Just to create a key for display (testing) $key = $otp->totp(Encoding::base32DecodeUpper($secret));
Sample script in example folder. Requires sessions to work (for secret storage).
Class Otp
Implements hotp according to RFC4226 and totp according to RFC6238 (only sha1, sha256 and sha512 algorithms). Once you have a secret, you can use it directly in this class to create the passwords themselves (mainly for debugging use) or use the check functions to safely check the validity of the keys. The checkTotp function also includes a helper to battle timedrift.
Class GoogleAuthenticator
Static function class to generate a correct url for the QR code, so you can easily scan it with your device. Google Authenticator is available as an application for iPhone and Android. This removes the burden to create such an app from the developers of websites by using this set of classes.
There are also older open source versions of the Google Authenticator app for both iPhone and Android.
About
Requirements
PHP >= 5.4.0
Uses paragonie/random_compat and paragonie/constant_time_encoding.
If you want to run the tests, PHPUnit >= 4.8.35 is required.
Author
Christian Riesen chris.riesen@gmail.com http://christianriesen.com
Acknowledgements
The classes have been inspired by many different places that were talking about otp and Google Authenticator. Thank you all for your help.
Project setup ideas blatantly taken from https://github.com/Seldaek/monolog
christian-riesen/otp 适用场景与选型建议
christian-riesen/otp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.46M 次下载、GitHub Stars 达 88, 最近一次更新时间为 2013 年 01 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「otp」 「hotp」 「totp」 「googleauthenticator」 「rfc4226」 「rfc6238」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 christian-riesen/otp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 christian-riesen/otp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 christian-riesen/otp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Security tools for PHP
Simple HOTP/TOTP generation library
A Google Authenticator Bundle for Symfony
Google Authenticator 2-factor authentication
Time-based One-time Password implementation for Nette framework
统计信息
- 总下载量: 5.46M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 93
- 点击次数: 41
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-29