PHPackages                             mariojgt/castle - 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. mariojgt/castle

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

mariojgt/castle
===============

Simple and easy 2 steps verification integration

2.0.10(1y ago)1174↓93.8%1MITCSSPHP ^8.0

Since Feb 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mariojgt/castle)[ Packagist](https://packagist.org/packages/mariojgt/castle)[ RSS](/packages/mariojgt-castle/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (2)Versions (14)Used By (1)

[![Logo](https://raw.githubusercontent.com/mariojgt/castle/main/Publish/Art/logo.png)](https://raw.githubusercontent.com/mariojgt/castle/main/Publish/Art/logo.png)

Castle
======

[](#castle)

This Laravel package help you quickly add 2fa authentication in you existing application, simular to google authentication.

Features
--------

[](#features)

- Demo with the example application flow you need.
- 2 steps autentication.
- middleware protection.

Badges
------

[](#badges)

[![MIT License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://choosealicense.com/licenses/mit/)[![version](https://camo.githubusercontent.com/5b43045fd2c0d2248fbad884c84f1c469e171d8256ee134a221c0c060afe0364/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6172696f6a67742f636173746c653f7374796c653d666f722d7468652d6261646765)](http://www.gnu.org/licenses/agpl-3.0)

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

[](#installation)

Install my-project with composer

```
  composer require mariojgt/castle
  php artisan install::castle
```

Usage/Examples
--------------

[](#usageexamples)

1: You need to assign the trait to you user model table in order to use the 2steps verification and have access to the backup codes.

```
use Mariojgt\Castle\Trait\Castle;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, Castle;

    /**
     * The attributes that are mass assignable.
     *
     * @var string[]
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];
```

this will insure you have access to the backup codes

2: In order to sync the user you need to first generate the authenticator secret using the helper normally when you register or with a controller method to sync the authenticator

```
use Mariojgt\Castle\Helpers\AuthenticatorHandle;

class myController
{
    public register () {
	    // Start the class that handle most of the logic
	    $handle = new AuthenticatorHandle();
	    // Generate the code
		$codeInfo =	    $handle->generateCode($userEmail);
		// Sync that code with the user using the trait
		Auth()->user()->syncAuthenticator($codeInfo['secret']);
    }
```

3: At this point the authenticator is enabled against that user, now you need to protect the middleware here is a example

```
// Auth Route Example
Route::group([
    'middleware' => ['web', '2fa'], // note you can use (2fa:admin) for admin guard or leave empty for web as default
], function () {
    // Example page required to be login
    Route::get('/castle-try', [HomeContoller::class, 'protected'])->name('castle.try');
});
```

4: Display the user codes, normaly you only display the backup codes once you can use the following example

```
Auth()->user()->getCodes; // this will return the backup codes for that user
```

5: using backup codes see the example

```
use Mariojgt\Castle\Helpers\AuthenticatorHandle;

myclass {

	public myFunction () {
		 // Start the class that handle most of the logic
		$handle = new AuthenticatorHandle();
		// the encryption is using the normal laravel encrypt fuction // example encrypt('user_secret')
		$handle->useBackupCode($codeYouType, $encryptauthenticatorSecret); // The second parameter is not required
	}

}
```

Tech Stack
----------

[](#tech-stack)

**Client:** TailwindCSS, vuejs, blade

**Server:** 2fa, Laravel

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Recently: every ~191 days

Total

13

Last Release

542d ago

Major Versions

1.0.2 → 2.0.02022-04-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/c75bb50805eab19dd419d846ba0a7178adac9b475f9787fc213d8be1262ece3c?d=identicon)[mariojgt](/maintainers/mariojgt)

---

Top Contributors

[![mariojgt](https://avatars.githubusercontent.com/u/7347012?v=4)](https://github.com/mariojgt "mariojgt (81 commits)")

---

Tags

2fa2factor2stepseasy-to-uselaravelphpsafetytwo-factor-authenticationtwo-steps-authenticationverificationlaravelauthenticator2steps2fa verification2fa authenticator

### Embed Badge

![Health badge](/badges/mariojgt-castle/health.svg)

```
[![Health](https://phpackages.com/badges/mariojgt-castle/health.svg)](https://phpackages.com/packages/mariojgt-castle)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.6M992](/packages/statamic-cms)[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[stephenjude/filament-two-factor-authentication

Filament Two Factor Authentication: Google 2FA + Passkey Authentication

84215.9k9](/packages/stephenjude-filament-two-factor-authentication)[jeffgreco13/filament-breezy

A custom package for Filament with login flow, profile and teams support.

1.0k2.1M61](/packages/jeffgreco13-filament-breezy)

PHPackages © 2026

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