PHPackages                             imseyed/auth2fa - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. imseyed/auth2fa

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

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.

v1.1.2(1y ago)21172MITPHPPHP &gt;=7.0

Since Aug 6Pushed 1y ago2 watchersCompare

[ Source](https://github.com/imseyed/Auth2FA)[ Packagist](https://packagist.org/packages/imseyed/auth2fa)[ Docs](https://github.com/imseyed/Auth2FA)[ RSS](/packages/imseyed-auth2fa/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Two-Factor Authentication (2FA) Library
=======================================

[](#two-factor-authentication-2fa-library)

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
--------

[](#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
-----

[](#usage)

### Install via composer:

[](#install-via-composer)

```
composer require imseyed/auth2fa

```

### TOTP Generation

[](#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](examples/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

[](#hotp-generation)

The `Auth2FA::HOTP` method generates an **HMAC-based One Time Password** using the provided secret key and counter value. [hotp.example.php](examples/hotp.example.php)

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

### Secret Key Generation

[](#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
-------

[](#license)

This library is released under the [MIT License](LICENSE).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

651d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/97f38f3e86fea9f3abe3de973707b6733e89a79b9a769664a728470f7080ed1d?d=identicon)[imseyed](/maintainers/imseyed)

---

Top Contributors

[![imseyed](https://avatars.githubusercontent.com/u/77242336?v=4)](https://github.com/imseyed "imseyed (4 commits)")

---

Tags

2faauthenticationhotpotp-verificationphptotphotptotpAuthentication2faTwo Factor Authentication

### Embed Badge

![Health badge](/badges/imseyed-auth2fa/health.svg)

```
[![Health](https://phpackages.com/badges/imseyed-auth2fa/health.svg)](https://phpackages.com/packages/imseyed-auth2fa)
```

###  Alternatives

[pragmarx/google2fa

A One Time Password Authentication package, compatible with Google Authenticator.

2.0k82.4M164](/packages/pragmarx-google2fa)[pragmarx/google2fa-qrcode

QR Code package for Google2FA

12124.6M37](/packages/pragmarx-google2fa-qrcode)[paragonie/multi-factor

Vendor-agnostic two-factor authentication library

142195.5k2](/packages/paragonie-multi-factor)[ellaisys/aws-cognito

AWS Cognito package that allows Auth and other related features using the AWS SDK for PHP

120220.7k1](/packages/ellaisys-aws-cognito)[lfkeitel/phptotp

TOTP/HOTP library for PHP

85434.7k2](/packages/lfkeitel-phptotp)[scheb/2fa-totp

Extends scheb/2fa-bundle with two-factor authentication using TOTP

292.7M22](/packages/scheb-2fa-totp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
