haikiri/simple-php-totp
最新稳定版本:1.2.1
Composer 安装命令:
composer require haikiri/simple-php-totp
包简介
Lightweight PHP TOTP (RFC 6238) and Base32 (RFC 4648) generation/decoding for 2FA authentication
关键字:
README 文档
README
Language: English | Русский
A lightweight and vanilla PHP library for generating TOTP (2FA) codes.
Compatibility
- PHP 7+ && PHP 8+
- Tests:
phpunit/phpunit(^9.6 || ^8.5 || ^6.5)
Installation
composer require haikiri/simple-php-totp
Usage example
<?php require __DIR__ . '/vendor/autoload.php'; use Haikiri\SimplePhpTotp\TOTP; # Generate a secret for storing in the DB. $secret = TOTP::generateSecret(); # Generate a 6-digit OTP code based on the secret. $code = TOTP::generate($secret); echo $secret . PHP_EOL; # Secret for the user. (needs be stored in the user's DB) echo $code . PHP_EOL; # TOTP-code with which we should compare the code provided by the user from the 2FA-app.
Get OTPAuth URL
<?php use Haikiri\SimplePhpTotp\TOTP; $url = TOTP::getTotpUrl( 'GJQTCOBSMI2TGZTD', # OTP-secret (Base32) 'user@example.com', # Username / client identifier 'My Service' # Issuer / organization name ); echo $url . PHP_EOL; # otpauth://totp/My%20Service:user%40example.com?secret=GJQTCOBSMI2TGZTD&issuer=My%20Service
统计信息
- 总下载量: 235
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-10