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

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

dmitrymomot/php-auth
====================

PHP Auth

v1.0.0(12y ago)1451MITPHPPHP &gt;=5.3.0

Since Apr 27Pushed 12y ago1 watchersCompare

[ Source](https://github.com/dmitrymomot/php-auth)[ Packagist](https://packagist.org/packages/dmitrymomot/php-auth)[ RSS](/packages/dmitrymomot-php-auth/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (3)Versions (3)Used By (1)

php-auth
========

[](#php-auth)

Simply authentication library

Key points:

- Supports drivers ('file' and 'database' adapters already included in the package).
- Easy to use
- Minimum configuration

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

[](#installation)

This package is available via Composer:

```
{
    "require": {
        "dmitrymomot/php-auth": "1.*"
    }
}
```

Example of usage
----------------

[](#example-of-usage)

### Usage adapter [File](https://github.com/dmitrymomot/php-auth/blob/master/src/Adapter/File.php)

[](#usage-adapter-file)

```
$auth = new \Auth\Adapter\File;
$auth->setUsers(array('test_user' => array('password' => 'hashed_password', 'role' => 'user')));
```

Log in

```
$auth->login('test_user', 'password'); // returns boolean value
```

Get user

```
$auth->getUser('guest') // returns current username or 'guest', if user isn't logged in
```

Get user role

```
$auth->getRole() // returns string
```

Check log in

```
$auth->loggedIn() // returned true
```

Check log in as

```
$auth->loggedIn('admin') // returned false
$auth->loggedIn('user') // returned true
```

Log out

```
$auth->logout(); // returns boolean value
```

Log in as another user

```
$auth->loginAs('username'); // returns boolean value
```

Come back to initial user

```
$auth->comeBack(); // returns boolean value
```

### Usage adapter [Database](https://github.com/dmitrymomot/php-auth/blob/master/src/Adapter/Database.php)

[](#usage-adapter-database)

*(supports all the same that 'file' adapter)*

In composer.json add package php-activerecord/php-activerecord

```
    "require": {
		"dmitrymomot/php-session": "1.*",
        "php-activerecord/php-activerecord":"dev-master"
    },
```

and update composer.

Set database config (read more in [php-activerecord docs](http://www.phpactiverecord.org/projects/main/wiki))

```
$cfg = \ActiveRecord\Config::instance();
$cfg->set_connections(array(
	'development' => 'mysql://username_for_dev:password@localhost/username_for_dev',
	'production' => 'mysql://username:password@localhost/database_name'
));
```

Initialization

```
$auth = new \Auth\Adapter\Database();
```

Initialization with custom model User

```
class CustomUser implements \Auth\Model\UserInterface {
	//....realisation of interface
}

$model = '\Custom\Model\CustomUser'; // full path to class
$auth = new \Auth\Adapter\Database($model);
```

Get user

```
$auth->getUser('guest') // returns instance of class \Auth\Model\User or 'guest', if user isn't logged in
```

Create new user

```
$auth->createUser(array('username' => 'test_user', 'password' => 'some_password', 'email' => 'user@mail.com', ...)); // returns boolean value or array error messages
```

Update current user

```
$auth->updateUser(array('username' => 'test_user', 'password' => 'some_password', ....)); // returns boolean value or array error messages
```

### Helpers

[](#helpers)

```
echo \Auth\Auth::hash('admin'); // returns hashed string 'admin'
```

Also you can set hash key

```
\Auth\Auth::hashKey = 'vv34r3v4c34r';
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/dmitrymomot/php-auth/blob/master/LICENSE) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

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

Unknown

Total

1

Last Release

4402d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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