PHPackages                             nacosvel/2fa - 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. nacosvel/2fa

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

nacosvel/2fa
============

Community-driven PHP library for generating OTPs (HOTP/TOTP), RFC-compliant and compatible with Google Authenticator.

v2.2.0(7mo ago)07.9kMITPHPPHP ^8.0

Since Aug 26Pushed 5mo agoCompare

[ Source](https://github.com/nacosvel/2fa)[ Packagist](https://packagist.org/packages/nacosvel/2fa)[ Docs](https://github.com/nacosvel/2fa)[ RSS](/packages/nacosvel-2fa/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

Nacosvel Authenticator
======================

[](#nacosvel-authenticator)

This community-driven PHP extension package provides secure one-time password (OTP) generation, implementing both HOTP (RFC 4226) and TOTP (RFC 6238) algorithms. Designed for reliability and interoperability, it ensures seamless compatibility with Google Authenticator and other industry-standard OTP solutions, making it ideal for implementing two-factor authentication (2FA) in PHP applications.

[![GitHub Tag](https://camo.githubusercontent.com/d2316753803aa116df1c4ef1c511b374bd61d1f3a0991d0997ab7ecb3bbbc030/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6e61636f7376656c2f326661)](https://github.com/nacosvel/2fa/tags)[![Total Downloads](https://camo.githubusercontent.com/d780dba1a3136c6921e623ea667233a38f0ea4c3edc17c16435d9c4983ccb774/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e61636f7376656c2f3266613f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nacosvel/2fa)[![Packagist Version](https://camo.githubusercontent.com/3a801d5d4014d53c7235c009b8d6344dcdcb30b2a073e992d85cfd8303693871/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e61636f7376656c2f326661)](https://packagist.org/packages/nacosvel/2fa)[![Packagist PHP Version Support](https://camo.githubusercontent.com/c7a3be18a4c2559e012ee75d232049f1c89c0afa8cd69ce8acbcd8a535dc4165/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e61636f7376656c2f326661)](https://github.com/nacosvel/2fa)[![Packagist License](https://camo.githubusercontent.com/ce31afd626bb8496d0bc13425b6006fd00fc7f73ab6fdfdce9e583e549f77bd3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e61636f7376656c2f326661)](https://github.com/nacosvel/2fa)

 Table of Contents1. [Installation](#installation)
2. [Usage](#usage)
3. [Contributing](#contributing)
4. [Contributors](#contributors)
5. [License](#license)

Installation
------------

[](#installation)

You can install the package via [Composer](https://getcomposer.org):

```
composer require nacosvel/2fa
```

\[[back to top](#readme-top)\]

Usage
-----

[](#usage)

### Generate Secret

[](#generate-secret)

```
use Nacosvel\Authenticator\Authentication;

$secret = Authentication::generateSecret(20, false);
// string(32) "RIPPSUOU3EQBR3FXML2QL43SRYGWCKY3"
```

### Generate Token

[](#generate-token)

```
use Nacosvel\Authenticator\HOTP;
use Nacosvel\Authenticator\TOTP;

$hotpToken = HOTP::generateToken($secret, 30, 6, 'sha1');
$totpToken = TOTP::generateToken($secret, 30, 6, 'sha1');
// string(6) "577349"
// string(6) "981726"
```

### Validate Token

[](#validate-token)

```
use Nacosvel\Authenticator\HOTP;
use Nacosvel\Authenticator\TOTP;

$hotpValidate = HOTP::validate($secret, $hotpToken, 30, 6, 'sha1', 3);
$totpValidate = TOTP::validate($secret, $totpToken, 30, 6, 'sha1', 3);
// bool(true)
// bool(true)
```

### Generate URI

[](#generate-uri)

```
use Nacosvel\Authenticator\HOTP;
use Nacosvel\Authenticator\TOTP;

$hotpURI = HOTP::buildURI($secret, 'Mr.Alex', 'Github', 30, 6, 'sha1')->toString();
$totpURI = TOTP::buildURI($secret, 'Mr.Alex', 'Github', 30, 6, 'sha1')->toString();
// string(118) "otpauth://hotp/Github:Mr.Alex?secret=LWN4DKX2KHW4X7VMSWNIRJVHW4F4SQ4Z&counter=30&digits=6&algorithm=sha1&issuer=Github"
// string(117) "otpauth://totp/Github:Mr.Alex?secret=RIPPSUOU3EQBR3FXML2QL43SRYGWCKY3&period=30&digits=6&algorithm=sha1&issuer=Github"
```

### URI::fromString

[](#urifromstring)

```
use Nacosvel\Authenticator\URI;

$uri = URI::fromString('otpauth://totp/Github:Mr.Alex?secret=RIPPSUOU3EQBR3FXML2QL43SRYGWCKY3&period=30&digits=6&algorithm=sha1&issuer=Github');
var_dump([
    'type'      => $uri->getType(),     // totp
    'issuer'    => $uri->getIssuer(),   // Github
    'account'   => $uri->getAccount(),  // Mr.Alex
    'secret'    => $uri->getSecret(),   // RIPPSUOU3EQBR3FXML2QL43SRYGWCKY3
    'digits'    => $uri->getDigits(),   // 6
    'algorithm' => $uri->getAlgorithm(),// sha1
]);
```

### URI::buildURI

[](#uribuilduri)

```
use Nacosvel\Authenticator\URI;
use Nacosvel\Authenticator\HOTP;
use Nacosvel\Authenticator\TOTP;

$hotpURI = URI::buildURI(HOTP::class, 'Mr.Alex', 'Github')->secret($secret)->toString();
$totpURI = URI::buildURI(TOTP::class, 'Mr.Alex', 'Github')->secret($secret)->toString();
// string(83) "otpauth://hotp/Github:Mr.Alex?secret=LWN4DKX2KHW4X7VMSWNIRJVHW4F4SQ4Z&issuer=Github"
// string(83) "otpauth://totp/Github:Mr.Alex?secret=RIPPSUOU3EQBR3FXML2QL43SRYGWCKY3&issuer=Github"
```

Contributing
------------

[](#contributing)

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

\[[back to top](#readme-top)\]

Contributors
------------

[](#contributors)

Thanks goes to these wonderful people:

[ ![contrib.rocks image](https://camo.githubusercontent.com/aa0c925690abb8b8df658c2ddd5d2c759358838eab956db4952c256b2ea3b2e5/68747470733a2f2f636f6e747269622e726f636b732f696d6167653f7265706f3d6e61636f7376656c2f326661)](https://github.com/nacosvel/2fa/graphs/contributors)Contributions of any kind are welcome!

\[[back to top](#readme-top)\]

License
-------

[](#license)

Distributed under the MIT License (MIT). Please see [License File](https://github.com/nacosvel/2fa/blob/main/LICENSE) for more information.

\[[back to top](#readme-top)\]

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance68

Regular maintenance activity

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 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 ~17 days

Total

4

Last Release

213d ago

Major Versions

v1.0.0 → v2.0.02025-08-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/2da9b458375a1b7972b7c4d26a5bf8f3e48db305e8805da36f253956f33c5568?d=identicon)[jundayw](/maintainers/jundayw)

---

Top Contributors

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

---

Tags

google authenticatorhotptotpRFC 6238RFC 42262faotps

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nacosvel-2fa/health.svg)

```
[![Health](https://phpackages.com/badges/nacosvel-2fa/health.svg)](https://phpackages.com/packages/nacosvel-2fa)
```

###  Alternatives

[spomky-labs/otphp

A PHP library for generating one time passwords according to RFC 4226 (HOTP Algorithm) and the RFC 6238 (TOTP Algorithm) and compatible with Google Authenticator

1.5k46.1M119](/packages/spomky-labs-otphp)[paragonie/multi-factor

Vendor-agnostic two-factor authentication library

142195.5k2](/packages/paragonie-multi-factor)[2amigos/2fa-library

2 Factor Authentication (2FA) library

34367.1k7](/packages/2amigos-2fa-library)[chillerlan/php-authenticator

A generator for counter- and time based 2-factor authentication codes (Google Authenticator). PHP 8.2+

58119.1k2](/packages/chillerlan-php-authenticator)[pedrosancao/php-otp

PHP implementation of HMAC-based one-time password algorithm according to RFC 4226 and RFC 6238 compatible with Google Authenticator

1863.8k](/packages/pedrosancao-php-otp)[scheb/2fa-google-authenticator

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

298.2M30](/packages/scheb-2fa-google-authenticator)

PHPackages © 2026

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