rych / otp
PHP实现的OATH一次性密码标准
v1.1.1
2015-06-30 03:38 UTC
Requires
- php: >=5.3.4
- ext-hash: *
- rych/random: 0.1.*
Requires (Dev)
- phpunit/phpunit: ~4.7
- satooshi/php-coveralls: ~0.6
This package is auto-updated.
Last update: 2024-09-23 10:57:08 UTC
README
此库提供了根据RFC 4226和RFC 6238定义的HMAC和时间基一次性密码功能,适用于PHP 5.3及以上版本。
安装
通过Composer
$ composer require rych/otp
使用方法
该库简化了生成和共享密钥的过程。
<?php use Rych\OTP\Seed; // Generates a 20-byte (160-bit) secret key $otpSeed = Seed::generate(); // -OR- use a pre-generated string $otpSeed = new Seed('ThisIsMySecretSeed'); // Display secret key details printf("Secret (HEX): %s\n", $otpSeed->getValue(Seed::FORMAT_HEX)); printf("Secret (BASE32): %s\n", $otpSeed->getValue(Seed::FORMAT_BASE32));
当用户尝试登录时,他们应被提示提供设备上显示的OTP。然后,该库可以使用用户的共享密钥验证提供的OTP。
<?php use Rych\OTP\HOTP; $otpSeed = $userObject->getOTPSeed(); $otpCounter = $userObject->getOTPCounter(); $providedOTP = $requestObject->getPost('otp'); // The constructor will accept a Seed object or a string $otplib = new HOTP($otpSeed); if ($otplib->validate($providedOTP, $otpCounter)) { // Advance the application's stored counter // This bit is important for HOTP but not done for TOTP $userObject->incrementOTPCounter($otplib->getLastValidCounterOffset() + 1); // Now the user is authenticated }
时间基OTP的处理方式相同,只是没有计数值来跟踪或递增。
变更日志
有关最近变更的更多信息,请参阅CHANGELOG。
测试
$ vendor/bin/phpunit -c phpunit.dist.xml
安全
如果您发现任何安全问题,请通过rchouinard@gmail.com发送电子邮件,而不是使用问题跟踪器。
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。