blar/otp

dev-master 2016-03-09 22:48 UTC

This package is auto-updated.

Last update: 2024-08-29 04:25:21 UTC


README

License Latest Stable Version Build Status Coverage Status Dependency Status Flattr

一次性密码 (OTP)

创建“基于时间的”一次性密码

设置

$otp = new Totp();
$otp->setLabel('username@example.com');
$otp->setIssuer('example.com');

创建密钥

密钥只需要每个用户创建一次。

$secret = $otp->createSecret();

分配密钥

$otp->setSecret($secret);

输出OTP-URL

$otp->getUrl();

该URL可能如下所示

otpauth://totp/username@example.com?
    issuer = example.com
    algorithm = SHA1
    digits = 6
    period = 30
    secret = LWZU3NR3PN5FXUX6XTHWE7OIWJEAFTWC

将OTP-URL作为QR码输出

某些认证器支持通过扫描QR码来传输设置。例如,可以使用blar/google-charts包生成QR码。

$qrcode = new Qrcode();
$qrcode->setSize(256, 256);
$qrcodeUrl = $qrcode->createUrl($otp->getUrl());

检查密码

$otp->validate($_POST['otp']);

Google-Authenticator

对于Google-Authenticator,需要执行以下设置,因为它使用了默认值,这些值不能通过otpauth-URL进行更改。

$otp->setAlgorithm('SHA1');
$otp->setDigits(6);
$otp->setInterval(30);