ideo / otpauth
为 TOTP 提供必要的处理。
0.1
2017-11-26 19:44 UTC
Requires
- php: >=5.6.4
- christian-riesen/base32: ^1.3.1
- endroid/qrcode: ^2.3.4
Requires (Dev)
- phpunit/phpunit: ^5.0|^6.0
This package is not auto-updated.
Last update: 2024-09-21 15:40:10 UTC
README
为 TOTP 提供必要的处理。
用于密钥生成和认证,它基于 google-authenticator 的实现。
用法
生成 TOTP 兼容应用的 QR 码。
$keyGenerator = new KeyGenerator();
$qrCodeGenerator = new QrCodeGenerator();
// Generate keys randomly, save this key in association with the target account.
$keyBytes = $keyGenerator->generateRandom(10);
$qrDataUri = $qrCodeGenerator->getQrCodeDataUri($keyBytes, 'sample@foo.bar', 'Sample');
使用密钥进行认证。
// It reads the key of the target account and compares it with the input pin.
$passcodeGenerator = new PasscodeGenerator(new HMacSigner($keyBytes));
$counter = new TotpCounter();
$time = time();
$valid = $passcodeGenerator->verifyTimeoutCode($pin, $counter->getValueAtTime($time));