PHPackages                             liquid-cats/g2fa - 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. liquid-cats/g2fa

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

liquid-cats/g2fa
================

Google 2FA

v1.0.2(3mo ago)0350MITPHPPHP &gt;=8.2CI passing

Since Dec 19Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/LiquidCats/g2fa)[ Packagist](https://packagist.org/packages/liquid-cats/g2fa)[ RSS](/packages/liquid-cats-g2fa/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

PHP Google 2FA and TOTP
=======================

[](#php-google-2fa-and-totp)

This repository was inspired by This library provides PHP classes for generating and verifying Time-Based One-Time Passwords (TOTP) as per the G2FA (Google Two Factor Authentication) standards. It includes TOTP and SecretKey classes designed to work together to offer a robust solution for two-factor authentication.

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

[](#installation)

```
composer require liquid-cats/g2fa
```

1. TOTP
-------

[](#1-totp)

This class is responsible for generating and verifying TOTPs based on a secret key and time.

### Features

[](#features)

Generates TOTPs for a given timestamp. Verifies TOTPs against the current or provided timestamp. Customizable algorithm, length, epoch, and period. Usage

```
Copy code
use LiquidCats\G2FA\TOTP;
use LiquidCats\G2FA\Enums\Algorithm;
use LiquidCats\G2FA\ValueObjects\SecretKey;

$totp = new TOTP(Algorithm::SHA512, 6, 30, 1);
$secretKey = new SecretKey('YOUR_SECRET_KEY');
$otp = $totp->now($secretKey);

// To verify OTP
$isValid = $totp->verify($secretKey, $otp);
```

2. SecretKey
------------

[](#2-secretkey)

The SecretKey class is used to handle secret keys required for generating TOTPs.

### Features

[](#features-1)

Validates secret keys for format and size. Decodes secret keys from Base32 encoding. Static method for generating new secret keys.

### Usage

[](#usage)

```
Copy code
use LiquidCats\G2FA\ValueObjects\SecretKey;

// Creating a SecretKey
$secretKey = new SecretKey('YOUR_SECRET_KEY');

// Decoding a SecretKey
$decodedKey = $secretKey->decode();

// Generating a new SecretKey
$newSecretKey = SecretKey::generate();
```

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

[](#contributing)

I welcome contributions and improvements to this library. Please submit pull requests or open issues for any bugs, feature requests, or enhancements.

License
-------

[](#license)

This project is open-sourced under the MIT License. See the LICENSE file for more details.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance80

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.1% 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 ~257 days

Total

4

Last Release

108d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e2bf38fc45dee94f8da383205f687795087b85684409e06e7deefae587075fe?d=identicon)[liquid-cats](/maintainers/liquid-cats)

---

Top Contributors

[![LiquidCats](https://avatars.githubusercontent.com/u/57875222?v=4)](https://github.com/LiquidCats "LiquidCats (33 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/liquid-cats-g2fa/health.svg)

```
[![Health](https://phpackages.com/badges/liquid-cats-g2fa/health.svg)](https://phpackages.com/packages/liquid-cats-g2fa)
```

###  Alternatives

[pragmarx/google2fa

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

2.0k82.4M164](/packages/pragmarx-google2fa)[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/halite

High-level cryptography interface powered by libsodium

1.2k9.4M63](/packages/paragonie-halite)[laragear/two-factor

On-premises 2FA Authentication for out-of-the-box.

339785.3k8](/packages/laragear-two-factor)[web-auth/webauthn-lib

FIDO2/Webauthn Support For PHP

1195.3M72](/packages/web-auth-webauthn-lib)[web-auth/webauthn-framework

FIDO2/Webauthn library for PHP and Symfony Bundle.

50570.7k1](/packages/web-auth-webauthn-framework)

PHPackages © 2026

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