PHPackages                             nocksapp/google2fa-laravel - 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. nocksapp/google2fa-laravel

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

nocksapp/google2fa-laravel
==========================

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

v0.1.2(8y ago)013BSD-3-ClausePHPPHP &gt;=5.4

Since Jun 20Pushed 8y ago1 watchersCompare

[ Source](https://github.com/nocksapp/google2fa-laravel)[ Packagist](https://packagist.org/packages/nocksapp/google2fa-laravel)[ RSS](/packages/nocksapp-google2fa-laravel/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (4)Used By (0)

Google2FA for Laravel
=====================

[](#google2fa-for-laravel)

[![Latest Stable Version](https://camo.githubusercontent.com/3be4878262c8c87315d056d95bbbf48fbd7881245c2ddfe847bdcf01c298172a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f707261676d6172782f676f6f676c653266612d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pragmarx/google2fa) [![License](https://camo.githubusercontent.com/a7d953c880516e66cbc40f3833498c010255e60ca0142114a22829dc66fe28e4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4253445f335f436c617573652d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE) [![Downloads](https://camo.githubusercontent.com/773eee7cb5dce0a1a11e4b7ca2c7761ab44bcf1a5ea705261eecfa5c59b4fc70/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f707261676d6172782f676f6f676c653266612d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pragmarx/google2fa) [![Code Quality](https://camo.githubusercontent.com/5d3950dc76c9c1973ebdd1cf1d65c687b267ca2990c8ca304c2de4b31b2e69cd/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616e746f6e696f7269626569726f2f676f6f676c653266612d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/antonioribeiro/google2fa/?branch=master) [![StyleCI](https://camo.githubusercontent.com/39bf2d37f18da1894eabadfff693c296004c18182aa98a7d1bdfb632e3fd21c5/68747470733a2f2f7374796c6563692e696f2f7265706f732f32343239363138322f736869656c64)](https://styleci.io/repos/24296182)

### Google Two-Factor Authentication for PHP Package for Laravel

[](#google-two-factor-authentication-for-php-package-for-laravel)

Google2FA is a PHP implementation of the Google Two-Factor Authentication Module, supporting the HMAC-Based One-time Password (HOTP) algorithm specified in [RFC 4226](https://tools.ietf.org/html/rfc4226) and the Time-based One-time Password (TOTP) algorithm specified in [RFC 6238](https://tools.ietf.org/html/rfc6238).

This package is a Laravel bridge to [Google2FA](https://github.com/antonioribeiro/google2fa)'s PHP package.

Demos, Example &amp; Playground
-------------------------------

[](#demos-example--playground)

Please check the [Google2FA Package Playground](https://pragmarx.com/google2fa).

[![playground](https://github.com/antonioribeiro/google2fa/raw/master/docs/playground.jpg)](https://github.com/antonioribeiro/google2fa/raw/master/docs/playground.jpg)

Here's an demo app showing how to use Google2FA: [google2fa-example](https://github.com/antonioribeiro/google2fa-example).

You can scan the QR code on [this (old) demo page](https://antoniocarlosribeiro.com/technology/google2fa) with a Google Authenticator app and view the code changing (almost) in real time.

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

[](#requirements)

- PHP 5.4+

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

[](#compatibility)

This package is compatible with

- Laravel 4.1+
- Laravel 5+

Installing
----------

[](#installing)

Use Composer to install it:

```
composer require pragmarx/google2fa-laravel

```

If you prefer inline QRCodes instead of a Google generated url, you'll need to install [BaconQrCode](https://github.com/Bacon/BaconQrCode):

```
composer require "bacon/bacon-qr-code":"~1.0"

```

Installing on Laravel
---------------------

[](#installing-on-laravel)

### Laravel 5.5

[](#laravel-55)

You don't have to do anything else, this package autoloads the Service Provider and create the Alias, using the new Auto-Discovery feature.

### Laravel 5.4 and below

[](#laravel-54-and-below)

Add the Service Provider and Facade alias to your `app/config/app.php` (Laravel 4.x) or `config/app.php` (Laravel 5.x):

```
PragmaRX\Google2FALaravel\ServiceProvider::class,

'Google2FA' => PragmaRX\Google2FALaravel\Facade::class,
```

Publish the config file
-----------------------

[](#publish-the-config-file)

```
php artisan vendor:publish --provider=PragmaRX\\Google2FALaravel\\ServiceProvider
```

Using It
--------

[](#using-it)

#### Use the Facade

[](#use-the-facade)

```
use Google2FA;

return Google2FA::generateSecretKey();
```

#### In Laravel you can use the IoC Container

[](#in-laravel-you-can-use-the-ioc-container)

```
$google2fa = app('pragmarx.google2fa');

return $google2fa->generateSecretKey();
```

Middleware
----------

[](#middleware)

This package has a middleware which will help you code 2FA on your app. To use it, you just have to:

Demo
----

[](#demo)

Click [here](https://pragmarx.com/google2fa/middleware) to see the middleware demo:

[![middleware](docs/middleware.jpg)](docs/middleware.jpg)

Using the middleware
--------------------

[](#using-the-middleware)

### Add the middleware to your Kernel.php:

[](#add-the-middleware-to-your-kernelphp)

```
protected $routeMiddleware = [
    ...
    '2fa' => \PragmaRX\Google2FALaravel\Middleware::class,
];
```

### Using it in one or more routes:

[](#using-it-in-one-or-more-routes)

```
Route::get('/admin', function () {
    return view('admin.index');
})->middleware(['auth', '2fa']);
```

### Configuring the view

[](#configuring-the-view)

You can set your 'ask for a one time password' view in the config file (config/google2fa.php):

```
/**
 * One Time Password View
 */
'view' => 'google2fa.index',
```

And in the view you just have to provide a form containing the input, which is also configurable:

```
/**
 * One Time Password request input name
 */
'otp_input' => 'one_time_password',
```

Here's a form example:

```

        Authenticate

```

One Time Password Lifetime
--------------------------

[](#one-time-password-lifetime)

Usually an OTP lasts forever, until the user logs off your app, but, to improve application safety, you may want to re-ask, only for the Google OTP, from time to time. So you can set a number of minutes here:

```
/**
* Lifetime in minutes.
* In case you need your users to be asked for a new one time passwords from time to time.
*/

'lifetime' => 0, // 0 = eternal
```

And you can decider whether your OTP will be kept alive while your users are browsing the site or not:

```
/**
 * Renew lifetime at every new request.
 */

'keep_alive' => true,
```

Manually logging out from 2Fa
-----------------------------

[](#manually-logging-out-from-2fa)

This command wil logout your user and redirect he/she to the 2FA form on the next request:

```
Google2FA::logout();
```

If you don't want to use the Facade, you may:

```
use PragmaRX\Google2FALaravel\Support\Authenticator;

(new Authenticator(request()))->logout();
```

Documentation
-------------

[](#documentation)

Check the ReadMe file in the main [Google2FA](https://github.com/antonioribeiro/google2fa) repository.

Tests
-----

[](#tests)

The package tests were written with [phpspec](http://www.phpspec.net/en/latest/).

Author
------

[](#author)

[Antonio Carlos Ribeiro](http://twitter.com/iantonioribeiro)

License
-------

[](#license)

Google2FA is licensed under the BSD 3-Clause License - see the `LICENSE` file for details

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

[](#contributing)

Pull requests and issues are more than welcome.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.7% 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 ~1 days

Total

3

Last Release

3243d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/02e2777bfbb48d2d0427eee1b911160c3616d6805531c952b7eb8d82f3cce76c?d=identicon)[nocksapp](/maintainers/nocksapp)

---

Top Contributors

[![antonioribeiro](https://avatars.githubusercontent.com/u/3182864?v=4)](https://github.com/antonioribeiro "antonioribeiro (44 commits)")[![it-can](https://avatars.githubusercontent.com/u/644288?v=4)](https://github.com/it-can "it-can (3 commits)")[![robertpcontreras-ts](https://avatars.githubusercontent.com/u/79461629?v=4)](https://github.com/robertpcontreras-ts "robertpcontreras-ts (1 commits)")

---

Tags

laravelAuthenticationTwo Factor Authenticationgoogle2fa

### Embed Badge

![Health badge](/badges/nocksapp-google2fa-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/nocksapp-google2fa-laravel/health.svg)](https://phpackages.com/packages/nocksapp-google2fa-laravel)
```

###  Alternatives

[pragmarx/google2fa-laravel

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

1.0k15.5M63](/packages/pragmarx-google2fa-laravel)[pragmarx/google2fa-qrcode

QR Code package for Google2FA

12024.6M37](/packages/pragmarx-google2fa-qrcode)[stephenjude/filament-two-factor-authentication

Filament Two Factor Authentication: Google 2FA + Passkey Authentication

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

PHPackages © 2026

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