imseyed/auth2fa 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

imseyed/auth2fa

最新稳定版本:v1.1.2

Composer 安装命令:

composer require imseyed/auth2fa

包简介

PHP library provides functionality for generating Time-based One Time Passwords (TOTP) and HMAC-based One Time Passwords (HOTP), commonly used in two-factor authentication (2FA) systems.

README 文档

README

This PHP library provides functionality for generating Time-based One Time Passwords (TOTP) and HMAC-based One Time Passwords (HOTP), commonly used in two-factor authentication (2FA) systems.

Features

  • TOTP Generation: Generate Time-based One Time Passwords.
  • HOTP Generation: Generate HMAC-based One Time Passwords.
  • Random Secret Key Generation: Generate random secret keys for use in TOTP and HOTP generation.

Usage

Install via composer:

composer require imseyed/auth2fa

TOTP Generation

The Auth2FA::TOTP method generates a Time-based One Time Password using the provided secret key and optional time slice. totp.example.php

$totp = imseyed\Auth2FA::TOTP($secret, $timeSlice);
/*
 $totp is a OPT code like: 458905
*/

If you want show expiration time of TOTP code must use Auth2FA::expire_time. that method return a number Unix timestamp.

$expirationTime = imseyed\Auth2FA::expire_time($timeSlice);
echo "Expire on ".date("H:i:s", $expirationTime)." (".($expirationTime - time())."s remind)";
/*
 $expirationTime is a unix timestamp like: 1722929683
*/

HOTP Generation

The Auth2FA::HOTP method generates an HMAC-based One Time Password using the provided secret key and counter value. hotp.example.php

$code = imseyed\Auth2FA::HOTP($secret, $counter);
/*
 $code is string like: 111222
*/

Secret Key Generation

The Auth2FA::generateSecret method generates a random secret key of the specified length.

$length = 16; // Secret key lenght
$secret = \imseyed\Auth2FA::generate_secret($length);
/*
 $secret is string like: OVZ7JFIPIXE4RTCE
*/

Note: There is no separate function to check the correctness of 2fa codes. You must use the generation functions to confirm the correctness of the codes sent by users.

License

This library is released under the MIT License.

统计信息

  • 总下载量: 127
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固