PHPackages                             riculum/php-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. riculum/php-auth

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

riculum/php-auth
================

A complete user authentication library written in PHP

v2.0.0(4y ago)3411MITPHP

Since Apr 15Pushed 4y ago2 watchersCompare

[ Source](https://github.com/Riculum/PHP-Auth)[ Packagist](https://packagist.org/packages/riculum/php-auth)[ RSS](/packages/riculum-php-auth/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

PHP-Auth
========

[](#php-auth)

A complete user authentication library written in PHP

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

[](#installation)

Use the package manager [composer](https://getcomposer.org) to install the library.

```
composer require riculum/php-auth
```

Initial setup
-------------

[](#initial-setup)

### Credentials

[](#credentials)

The basic database settings can be set through environment variables. Add a `.env` file in the root of your project. Make sure the `.env` file is added to your `.gitignore` so it is not checked-in the code. By default, the library looks for the following variables:

- DB\_HOST
- DB\_NAME
- DB\_USERNAME
- DB\_PASSWORD
- DB\_PREFIX

More information how to use environment variables [here](https://github.com/vlucas/phpdotenv)

### Database

[](#database)

```
CREATE TABLE IF NOT EXISTS user (
    id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    uuid VARCHAR(50) NOT NULL UNIQUE,
    firstname VARCHAR(50) NOT NULL,
    lastname VARCHAR(50) NOT NULL,
    email VARCHAR(100) NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL,
    token VARCHAR(255) NOT NULL,
    attempts TINYINT NOT NULL DEFAULT 0,
    online TINYINT NOT NULL DEFAULT 0,
    verified TINYINT NOT NULL DEFAULT 0,
    enabled TINYINT NOT NULL DEFAULT 1,
    updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    createdAt DATETIME DEFAULT CURRENT_TIMESTAMP
)
```

*Note: We recommend to set a database prefix*

### Configuration

[](#configuration)

Import vendor/autoload.php and load the `.env` settings

```
require_once 'vendor/autoload.php';

use Auth\Core\Authentication as Auth;

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
```

Usage
-----

[](#usage)

### Registration

[](#registration)

Use an associative array with user data to register a new user

```
$user = array(
    'firstname' => 'John',
    'lastname' => 'Doe',
    'email' => 'john.doe@example.com', //must be unique
    'password' => '$2y$10$jNtkQSKNni2ELyoi9Y/lpedy7v92FYzqz5ePm1M6jPGY9hb8TCmAq',
    'token' => md5(uniqid(rand(), true))
);

try {
    echo Auth::register($user);
} catch (UserAlreadyExistsException $e) {
    echo 'User with the specified email address already exists';
} catch (Exception $e) {
    echo "Something went wrong";
}
```

### Login

[](#login)

```
try {
    Auth::login('john.doe@example.com', '123456');
    echo 'Login successful';
} catch (InvalidEmailException | InvalidPasswordException $e) {
    echo 'Email or Password are wrong';
} catch(UserNotEnabledException $e) {
    echo 'User account has been deactivated';
} catch (TooManyAttemptsException $e) {
    echo 'Too many failed login attempts';
} catch (Exception $e) {
    echo "Something went wrong";
}
```

### Verify

[](#verify)

```
if (Auth::verify()) {
    echo "Authorization successful";
} else {
    echo "Authorization failed";
}
```

### Logout

[](#logout)

```
try {
    Auth::logout();
} catch (Exception $e) {
    echo 'Something went wrong';
}
```

Bugreport &amp; Contribution
----------------------------

[](#bugreport--contribution)

If you find a bug, please either create a ticket in github, or initiate a pull request

Versioning
----------

[](#versioning)

We adhere to semantic (major.minor.patch) versioning (). This means that:

- Patch (x.x.patch) versions fix bugs
- Minor (x.minor.x) versions introduce new, backwards compatible features or improve existing code.
- Major (major.x.x) versions introduce radical changes which are not backwards compatible.

In your automation or procedure you can always safely update patch &amp; minor versions without the risk of your application failing.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

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

Total

6

Last Release

1504d ago

Major Versions

v1.1.3 → v2.0.02022-05-21

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

authentificationphpphp-login

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/riculum-php-auth/health.svg)

```
[![Health](https://phpackages.com/badges/riculum-php-auth/health.svg)](https://phpackages.com/packages/riculum-php-auth)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[descope/descope-php

Descope SDK for PHP

4223.8k](/packages/descope-descope-php)

PHPackages © 2026

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