PHPackages                             raktfranhjartat/small-mvc-auth - 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. raktfranhjartat/small-mvc-auth

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

raktfranhjartat/small-mvc-auth
==============================

A simple Auth plugin for PHP

01PHP

Since May 31Pushed 1mo agoCompare

[ Source](https://github.com/raktfranhjartat/small-mvc-auth)[ Packagist](https://packagist.org/packages/raktfranhjartat/small-mvc-auth)[ RSS](/packages/raktfranhjartat-small-mvc-auth/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Small MVC Auth
==============

[](#small-mvc-auth)

[![PHP Version Requirement](https://camo.githubusercontent.com/ccede4153882bb7bb7a5e6ee36d423a63ce0218c8510dfba12146e167719e0ef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344253230382e302d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/ccede4153882bb7bb7a5e6ee36d423a63ce0218c8510dfba12146e167719e0ef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344253230382e302d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)[![License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)[![Composer](https://camo.githubusercontent.com/d9e631c44007b6dae400a304bcd224c63194e6303d118b31cafde8c0229e4d52/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6d706f7365722d52656164792d626c75653f6c6f676f3d636f6d706f736572266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/d9e631c44007b6dae400a304bcd224c63194e6303d118b31cafde8c0229e4d52/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6d706f7365722d52656164792d626c75653f6c6f676f3d636f6d706f736572266c6f676f436f6c6f723d7768697465)

A lightweight, lightning-fast, and fully "headless" authentication plugin tailored for custom-built PHP MVC frameworks.

The package handles all underlying logic for secure login, database validation, and sessions, but leaves all design, HTML, and CSS (UI) entirely up to you and your application. The perfect drop-in package when you want rock-solid authentication without being forced into a specific frontend library.

✨ Features
----------

[](#-features)

- **100% Headless:** No baked-in HTML. Works seamlessly with Bootstrap, Tailwind, Vue, React, or plain HTML.
- **Secure "Remember Me":** Built-in support for auto-login via secure, token-based HttpOnly cookies (protects against XSS and Cookie Forgery).
- **Dependency Injection:** Completely independent of your framework's underlying structure. You inject your own database connection.
- **Intended URL ("Smart Redirects"):** Automatically saves the URL the user attempted to access before being redirected to the login, and routes them to the correct destination upon successful login.
- **Rock-Solid Encryption:** Built on PHP's native and industry-standard `password_hash()` and `password_verify()`.

---

📦 Installation
--------------

[](#-installation)

Install the package via Composer in your project:

```
composer require raktfranhjartat/small-mvc-auth
```

🚀 Getting Started
-----------------

[](#-getting-started)

### 1. Prepare the Database

[](#1-prepare-the-database)

The package expects you to have a table (e.g., users) with at least these three columns:

- email (VARCHAR, UNIQUE)
- password\_hash (VARCHAR)
- remember\_token (VARCHAR, NULL) - *Used for the secure cookie.*

> **Tip:** To create your first test password, you can run echo password\_hash('your\_password', PASSWORD\_DEFAULT); in a temporary PHP file and insert the result directly into the database.

### 2. Initialize the Package

[](#2-initialize-the-package)

Import AuthManager into your application and pass your existing database connection (PDO or your custom database wrapper).

```
use Raktfranhjartat\SmallMvcAuth\AuthManager;
use App\Core\Database; // Replace with your framework's database class

// Start your database (fetches config for 'app')
$db = new Database('app');

// Initialize the authentication package
$auth = new AuthManager($db);
```

### 3. Protect a Route (Middleware)

[](#3-protect-a-route-middleware)

To lock a controller or method so that only logged-in users have access, call requireLogin(). If the user is not logged in, their requested URL is saved in the session, and they are redirected directly to /login.

```
// Inside your Controller, before loading the view
$auth->requireLogin('/login');

// The code below only runs if the user is confirmed as logged in
```

### 4. Handle the Login

[](#4-handle-the-login)

When your application receives a login form via POST, use attempt() to verify the credentials against the database. If the login is successful, you can use the smart intendedUrl() function to send the user back exactly where they were headed.

```
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$type = 'email' // set to username if left empty
$remember = isset($_POST['remember']); // true if the checkbox is checked

if ($auth->attempt($email, $password, $type, $remember)) {
    // Retrieves the URL they tried to reach, otherwise redirects to /admin
    $redirectUrl = $auth->intendedUrl('/admin');

    // Use the framework's built-in redirect method
    $this->redirect($redirectUrl, ['success' => 'You are logged in!']);
    return;
} else {
    // Incorrect email or password, redirect back to the form
    $this->redirect('/login', ['error' => 'Incorrect email or password.']);
    return;
}
```

🤝 Contributing
--------------

[](#-contributing)

Pull requests are very welcome! If you find a bug or have suggestions for new features, please open an "Issue" first so we can discuss it. Make sure to follow the code standards before pushing your PR.

📄 License
---------

[](#-license)

This project is open-source and released under the MIT License. You are free to use, modify, and distribute the code, even in commercial projects.

```

```

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance59

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/63348195?v=4)[raktfranhjartat](/maintainers/raktfranhjartat)[@raktfranhjartat](https://github.com/raktfranhjartat)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/raktfranhjartat-small-mvc-auth/health.svg)

```
[![Health](https://phpackages.com/badges/raktfranhjartat-small-mvc-auth/health.svg)](https://phpackages.com/packages/raktfranhjartat-small-mvc-auth)
```

###  Alternatives

[vitalybaev/laravel5-dkim

Laravel 5/6 package for signing outgoing messages with DKIM.

3163.1k](/packages/vitalybaev-laravel5-dkim)[firemultimedia/mautic-multi-captcha-bundle

This plugin brings Google's reCAPTCHA, hCaptcha, and Cloudflare Turnstile integration to mautic.

141.3k](/packages/firemultimedia-mautic-multi-captcha-bundle)

PHPackages © 2026

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