theodorejb / multi-factor
无需厂商依赖的两因素认证库
v2.0.0
2024-09-22 16:18 UTC
Requires
- php: >=8.1
- bacon/bacon-qr-code: ^3.0
- paragonie/constant_time_encoding: ^3.0
Requires (Dev)
- phpunit/phpunit: ^10.5
- psalm/plugin-phpunit: ^0.19.0
- vimeo/psalm: ^5.26
This package is auto-updated.
Last update: 2024-09-22 16:19:52 UTC
README
设计为各种双因素认证解决方案的无厂商依赖实现。
由 paragonie/multi_factor 衍生而来。最初由 Paragon Initiative Enterprises 为其自有项目开发。由于原始项目未得到维护,因此进行了分支以支持 PHP 8+。
采用双重许可证:GPL 和 MIT。与所有双重许可项目一样,您可以根据需要选择合适的许可证。
要求
- PHP 8.1+
安装
composer require theodorejb/multi-factor
示例用法
显示二维码
<?php use ParagonIE\MultiFactor\Vendor\GoogleAuth; $seed = random_bytes(20); $auth = new GoogleAuth($seed); $auth->makeQRCode(null, 'php://output', 'email@example.com', 'Issuer', 'Label');
验证双因素代码
<?php use ParagonIE\MultiFactor\OneTime; use ParagonIE\MultiFactor\OTP\TOTP; // You can use TOTP or HOTP $otp = new OneTime($seed, new TOTP()); if (\password_verify($_POST['password'], $storedHash)) { if ($otp->validateCode($_POST['2facode'], time())) { // Login successful } }