PHPackages                             scriptoshi/livewire-2fa - 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. scriptoshi/livewire-2fa

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

scriptoshi/livewire-2fa
=======================

Simple two-factor authentication package for Laravel 12 using Livewire

1.0.0(1y ago)94.8k↓42.9%1[1 PRs](https://github.com/scriptoshi/livewire-2fa/pulls)MITPHPPHP ^8.2

Since Mar 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/scriptoshi/livewire-2fa)[ Packagist](https://packagist.org/packages/scriptoshi/livewire-2fa)[ RSS](/packages/scriptoshi-livewire-2fa/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (3)Used By (0)

Laravel Livewire 2FA
====================

[](#laravel-livewire-2fa)

A simple and elegant two-factor authentication package for Laravel 12 using Livewire and Flux components. Built to work seamlessly with Laravel 12's authentication stack.

Overview
--------

[](#overview)

Laravel 2FA provides an easy way to add Google Authenticator compatible two-factor authentication to your Laravel 12 application. Built with Livewire and Flux components, it offers a modern, interactive user experience with minimal configuration.

### Features

[](#features)

- 🔒 Google Authenticator compatible (TOTP)
- ⚡ Livewire-powered interactive components
- 🎨 Beautiful UI with Flux components
- 🌓 Full dark mode support
- 🛠️ Simple integration with existing authentication systems
- 🔑 Recovery codes for account access backup
- 🛡️ On-demand password and 2FA confirmation modals
- 🔄 Compatible with Laravel 12 and Livewire 3

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

[](#requirements)

- PHP 8.2+
- Laravel 12.x
- Livewire 3.x
- Flux components

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

[](#installation)

### 1. Install the package via Composer

[](#1-install-the-package-via-composer)

```
composer require scriptoshi/livewire-2fa
```

### 2. (optional) If you need to customize, publish the assets

[](#2-optional-if-you-need-to-customize-publish-the-assets)

```
php artisan vendor:publish --provider="Scriptoshi\Livewire2fa\TwoFactorAuthServiceProvider" --tag="config"
php artisan vendor:publish --provider="Scriptoshi\Livewire2fa\TwoFactorAuthServiceProvider" --tag="views"
php artisan vendor:publish --provider="Scriptoshi\Livewire2fa\TwoFactorAuthServiceProvider" --tag="migrations"
```

### 3. Run the migrations

[](#3-run-the-migrations)

This will add the required columns to your users table.

```
php artisan migrate
```

### 4. Include the TwoFactorAuthenticatable trait in your User model

[](#4-include-the-twofactorauthenticatable-trait-in-your-user-model)

```
use Scriptoshi\Livewire2fa\Traits\TwoFactorAuthenticatable;

class User extends Authenticatable
{
    use TwoFactorAuthenticatable;

    // ...
}
```

Configuration
-------------

[](#configuration)

The package comes with sensible defaults, but you can customize it using the corresponding `.env` variables. Add the following lines to your .env to customise the config

```
# Enable or disable 2FA functionality entirely
TWO_FACTOR_AUTH_ENABLED=true
# Require users to confirm their 2FA setup with a code
TWO_FACTOR_AUTH_CONFIRM=true
# How many OTP codes will be accepted (time window)
TWO_FACTOR_AUTH_WINDOW=1
# Number of recovery codes to generate
TWO_FACTOR_AUTH_RECOVERY_CODE_COUNT=8
# Timeout for 2FA verification (in seconds, default 15 minutes)
TWO_FACTOR_AUTH_TIMEOUT=600
```

Basic Usage
-----------

[](#basic-usage)

### Adding 2FA Management to User Profile

[](#adding-2fa-management-to-user-profile)

Add the Livewire component to your user profile page:

```

```

On Laravel 12 Starter kit:

1. Edit `resources/views/components/settings/layout.blade.php` and add:

```

    {{ __('Profile') }}
    {{ __('Password') }}
    {{ __('Appearance') }}

    {{ __('Two factor Auth') }}

```

2. Create the two factor auth view: `resources/views/livewire/settings/twofactor.blade.php`

```
