PHPackages                             iago-effting/two-factor-api - 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. iago-effting/two-factor-api

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

iago-effting/two-factor-api
===========================

Provides two-factor authenticaton for Laravel

v0.0.26(10y ago)225MITPHP

Since Oct 14Pushed 10y ago1 watchersCompare

[ Source](https://github.com/iagoEffting/TwoFactorAPI)[ Packagist](https://packagist.org/packages/iago-effting/two-factor-api)[ RSS](/packages/iago-effting-two-factor-api/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

[![Code Climate](https://camo.githubusercontent.com/13f7e006c439804da540d226fcb9a31392ee193847753fbfbb101036e95d3bbc/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6961676f45666674696e672f54776f466163746f724150492f6261646765732f6770612e737667)](https://codeclimate.com/github/iagoEffting/TwoFactorAPI)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/58f19da8f4ac4d4becff0dd7f34888def9ac1e145173c74752b3405611eac98b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6961676f45666674696e672f54776f466163746f724150492f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/iagoEffting/TwoFactorAPI/?branch=master)[![Build Status](https://camo.githubusercontent.com/9ead6db32d6041dafd494f7b404081594629a4fa8a0aa536c7339bd0df4c7102/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6961676f45666674696e672f54776f466163746f724150492f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/iagoEffting/TwoFactorAPI/build-status/master)\#TwoFactorAPI Two Factor API is a library to improve security authentication APIs. We use the system OTP (one-time password) a password that expires after some time. This implementation uses Google Autenticator to generate passwords in your mobile application.

How does it work:

Requirements
------------

[](#requirements)

- PHP 5.4+

Compatibility
-------------

[](#compatibility)

- Laravel 5.1+

Installing
----------

[](#installing)

### 1. Dependency

[](#1-dependency)

```
composer require iago-effting/two-factor-api

```

or manually

```
{
    "require": {
        "iago-effting/two-factor-api": "dev-master"
    }
}

```

### 2. Provider

[](#2-provider)

Add Service Provider and Facade to your `config/app.php`

```
IagoEffting\TwoFactorAPI\Providers\TwoFactorApiServiceProvider::class
...
'TwoFactor'  => \IagoEffting\TwoFactorAPI\Facades\TwoFactor::class
```

### 3. Middleware
Add middleware to your `app\Http\kernel.php` in variable `$routeMiddleware`
```
// Access using TwoFactor
'needTwoFactor' => \IagoEffting\TwoFactorAPI\Middleware\TwoFactorAuthenticate::class,
```
### 4. User Class
On your User class, add the trait IagoEffting\TwoFactorAPI\Traits\HasTwoFacto to enable the creation of secret key:
```
namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Artesaos\Defender\Traits\HasDefender;
use IagoEffting\TwoFactorAPI\Traits\HasTwoFactor;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{

  use Authenticatable, CanResetPassword, HasTwoFactor;
...
```

### 5. Publishing configuration file and migrations
Publish the configs and migrates
```
php artisan vendor:publish
```

Run migrate

```

php artisan migrate

```

## Usage
### Facade
Generate secret key

```

TwoFactor::generateKey(); =&gt; 53TNJZF7GYDKJ2EEOWWZM7KFRMJJMJB5

```

Generate QR Code for synchronize in your Google Authentica

```

TwoFactor::generateQrCode(\['mail' =&gt; '', 'key' =&gt; '53TNJZF7GYDKJ2EEOWWZM7KFRMJJMJB5'\]) =&gt; [https://chart.googleapis.com/chart?chs=200x200&amp;chld=M|0&amp;cht=qr&amp;chl=otpauth%3A%2F%2Ftotp%2FiNeural%3Aiago2222marina%40gmail.com%3Fsecret%3D53TNJZF7GYDKJ2EEOWWZM7KFRMJJMJB5%26issuer%3DiNeural](https://chart.googleapis.com/chart?chs=200x200&chld=M%7C0&cht=qr&chl=otpauth%3A%2F%2Ftotp%2FiNeural%3Aiago2222marina%40gmail.com%3Fsecret%3D53TNJZF7GYDKJ2EEOWWZM7KFRMJJMJB5%26issuer%3DiNeural)

```

Verify that the key generated by Google Authenticator

```

TwoFactor::verifyKey($user, $secret); =&gt; true

```

Attach in a User

```

$secret = new Secret(); $secret-&gt;key = TwoFactor::generateKey();

$user = User::find(1); $user-&gt;secret()-&gt;save($secret);

```

```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

3916d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3be4b04f687058827c597f9ca19d92a1223d7499167a39525ea9810e2287b52e?d=identicon)[iagoEffting](/maintainers/iagoEffting)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/iago-effting-two-factor-api/health.svg)

```
[![Health](https://phpackages.com/badges/iago-effting-two-factor-api/health.svg)](https://phpackages.com/packages/iago-effting-two-factor-api)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[directorytree/ldaprecord-laravel

LDAP Authentication &amp; Management for Laravel.

5752.3M18](/packages/directorytree-ldaprecord-laravel)[illuminate/auth

The Illuminate Auth package.

10528.2M1.2k](/packages/illuminate-auth)[hasinhayder/tyro-login

Tyro Login - Beautiful, customizable authentication views for Laravel 12 &amp; 13

2464.9k6](/packages/hasinhayder-tyro-login)[stephenjude/filament-two-factor-authentication

Filament Two Factor Authentication: Google 2FA + Passkey Authentication

84215.9k9](/packages/stephenjude-filament-two-factor-authentication)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

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