如何在PHP中使用TOTP / HOTP库

时间:2017-06-02 17:49:18

标签: php one-time-password

我尝试将TOTP PHP库实现为我的登录表单的另一种身份验证。我下载并遵循github的安装说明,如下面的代码:

<?php
include('src/Factory.php');
include('src/HOTP.php');
include('src/HOTPInterface.php');
include('src/OTP.php');
include('src/OTPInterface.php');
include('src/ParameterTrait.php');
include('src/TOTP.php');
include('src/TOTPInterface.php');
use OTPHP\TOTP;

$otp = TOTP::create();
echo 'The current OTP is: '.$otp->now();
?>

然而,我最终收到了错误消息Warning: Unsupported declare 'strict_types' in C:\wamp64\www\otp\src\HOTP.php on line 3Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in C:\wamp64\www\otp\src\HOTP.php on line 28

我无法弄清楚为什么会这样。非常感谢您的帮助。感谢。

2 个答案:

答案 0 :(得分:1)

尝试兼容PHP 5.x的multiOTP类 https://github.com/multiOTP/multiotp

答案 1 :(得分:1)

安装较低版本的软件包,如~8.0,适用于PHP 5.5

https://github.com/Spomky-Labs/otphp/blob/v8.3.2/composer.json#L19

在composer.json

中添加此内容

"require": { "spomky-labs/otphp": "~8.3" }

或使用此链接将其下载为ZIP并手动将其添加到您的项目中

https://github.com/Spomky-Labs/otphp/archive/v8.3.2.zip

更好的是使用composer,因为你有自动加载器。 :)这样就不需要手动要求文件了。