PHPackages                             laragear/two-factor - 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. laragear/two-factor

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

laragear/two-factor
===================

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

v4.0.0(2mo ago)339785.3k—0.2%24[1 PRs](https://github.com/Laragear/TwoFactor/pulls)7MITPHPPHP ^8.3CI passing

Since Feb 16Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/Laragear/TwoFactor)[ Packagist](https://packagist.org/packages/laragear/two-factor)[ Fund](https://github.com/sponsors/DarkGhostHunter)[ Fund](https://paypal.me/darkghosthunter)[ RSS](/packages/laragear-two-factor/feed)WikiDiscussions 4.x Synced 1mo ago

READMEChangelog (10)Dependencies (24)Versions (28)Used By (7)

Two Factor
==========

[](#two-factor)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6ed9fbae48a0ff74dbf4c72349967502123a0eb26698cc14ea4a15208f8e3e65/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c617261676561722f74776f2d666163746f722e737667)](https://packagist.org/packages/laragear/two-factor)[![Latest stable test run](https://github.com/Laragear/TwoFactor/workflows/Tests/badge.svg)](https://github.com/Laragear/TwoFactor/actions)[![Codecov Coverage](https://camo.githubusercontent.com/35935015abe27277f9328506817ac38d74f68e2a1c596d0d398ee28f06bbc644/68747470733a2f2f636f6465636f762e696f2f67682f4c617261676561722f54776f466163746f722f67726170682f62616467652e7376673f746f6b656e3d424a4d42565a4e504d38)](https://codecov.io/gh/Laragear/TwoFactor)[![Maintainability](https://camo.githubusercontent.com/4e49b10234188f6dff6a63afd73ddddf911fc77f3f400a1ffa9e29b2465cbae4/68747470733a2f2f716c74792e73682f6261646765732f65623965633164632d343538372d343663632d393236312d3664656134303565306237362f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/Laragear/projects/TwoFactor)[![Sonarcloud Status](https://camo.githubusercontent.com/f6b0ca8f10c562e053b3665b2aa323fa36020e5550b16386eac1ef45d33551cc/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d4c617261676561725f54776f466163746f72266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=Laragear_TwoFactor)[![Laravel Octane Compatibility](https://camo.githubusercontent.com/70359a356da237cd29561bc5d0bb80baae775b5ff62f288ed324755382858342/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2532304f6374616e652d436f6d70617469626c652d737563636573733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://laravel.com/docs/11.x/octane#introduction)

On-premises Two-Factor Authentication for all your users out of the box.

```
use Illuminate\Http\Request;
use Laragear\TwoFactor\Facades\Auth2FA;

public function login(Request $request)
{
    $attempt = Auth2FA::attempt($request->only('email', 'password'));

    if ($attempt) {
        return 'You are logged in!';
    }

    return 'Hey, you should make an account!';
}
```

This package enables TOTP authentication using 6 digits codes. No need for external APIs.

Tip

Want to authenticate users with Passkeys? Check out [Laragear WebAuthn](https://github.com/Laragear/WebAuthn).

Become a sponsor
----------------

[](#become-a-sponsor)

[![](.github/assets/support.png)](https://github.com/sponsors/DarkGhostHunter)

Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can **spread the word on social media!**

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

[](#requirements)

- PHP 8.3 or later
- Laravel 12 or later

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

[](#installation)

Fire up Composer and require this package in your project.

```
composer require laragear/two-factor
```

That's it.

### How this works

[](#how-this-works)

This package adds a **Contract** to detect if a user, after the credentials are deemed valid, should use Two-Factor Authentication as a second layer of authentication.

It includes a custom **view** and a **helper** to handle the Two-Factor authentication itself during login attempts.

Works without middleware or new guards, but you can go full manual if you want.

Set up
------

[](#set-up)

1. First, install the migration, translations, views and config into your application, with the `two-factor:install` Artisan command.

```
php artisan two-factor:install
```

Tip

You can [edit the migration](DATABASE.md) by adding new columns before migrating, and also change the [table name](DATABASE.md#model-customization).

After that, you may migrate your table like always through the Artisan command.

```
php artisan migrate
```

2. Add the `TwoFactorAuthenticatable` *contract* and the `TwoFactorAuthentication` trait to the User model, or any other model you want to make Two-Factor Authentication available.

```
