PHPackages                             promocat/yii2-twofa - 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. promocat/yii2-twofa

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

promocat/yii2-twofa
===================

Provides TOTP and QR codes for use with an authenticator like the one from Google or Authy

0.1.3(2y ago)924.2k↓50%7[1 PRs](https://github.com/promocat/yii2-twofa/pulls)MITPHPPHP ^7.4

Since Nov 4Pushed 2y ago2 watchersCompare

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

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

Extension for Yii2 providing Two Factor Authentication
======================================================

[](#extension-for-yii2-providing-two-factor-authentication)

Provides TOTP and QR codes for use with an authenticator like the one from Google or Authy

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist promocat/yii2-twofa "*"

```

or add

```
"promocat/yii2-twofa": "*"

```

to the require section of your `composer.json` file.

Setup
-----

[](#setup)

Update the user component in your config file to use the class

```
promocat\twofa\User::class

```

It should sorta look like this

```
'components' => [
    'user' => [
        'class' => promocat\twofa\User::class,
        'identityClass' => 'common\models\User',
        'enableAutoLogin' => true,
        'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
    ]
]

```

Also add the "twoFa" component:

```
'twoFa' => ['class' => promocat\twofa\TwoFa::class]

```

Next, add the TwoFaBehavior to your User model

```
public function behaviors() {
    return [
        'two_fa' => ['class' => TwoFaBehavior::class]
    ];
}

```

Usage
-----

[](#usage)

Congratulations, you can now, for example, call

```
Yii::$app->twofa->generateSecret()

```

or

```
Yii::$app->twofa->checkCode($secret, $code);

```

Use

```
promocat\models\TwoFaForm

```

for the 2FA activation and verification forms. Or at least let is be an example.

QR Code Widget
--------------

[](#qr-code-widget)

```

```

How to functionally implement:
------------------------------

[](#how-to-functionally-implement)

See "example.php" to get started.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity37

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

Total

2

Last Release

972d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3056188?v=4)[Brandon Tilstra](/maintainers/C4RoCKeT)[@C4RoCKeT](https://github.com/C4RoCKeT)

---

Top Contributors

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

---

Tags

qrgoogle authenticatorotptotp2faTwo Factor Authenticationyii2authy

### Embed Badge

![Health badge](/badges/promocat-yii2-twofa/health.svg)

```
[![Health](https://phpackages.com/badges/promocat-yii2-twofa/health.svg)](https://phpackages.com/packages/promocat-yii2-twofa)
```

###  Alternatives

[stephenjude/filament-two-factor-authentication

Filament Two Factor Authentication: Google 2FA + Passkey Authentication

81158.7k4](/packages/stephenjude-filament-two-factor-authentication)[paragonie/multi-factor

Vendor-agnostic two-factor authentication library

142195.5k2](/packages/paragonie-multi-factor)[remotemerge/totp-php

Lightweight, fast, and secure TOTP (2FA) authentication library for PHP — battle tested, dependency free, and ready for enterprise integration.

2010.2k](/packages/remotemerge-totp-php)

PHPackages © 2026

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