PHPackages                             atk4/login - 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. [Framework](/categories/framework)
4. /
5. atk4/login

ActiveLibrary[Framework](/categories/framework)

atk4/login
==========

Login and User module for Agile UI

6.0.0(6mo ago)2518.5k23[4 issues](https://github.com/atk4/login/issues)5MITPHPPHP &gt;=7.4 &lt;8.5CI failing

Since Dec 30Pushed 6mo ago8 watchersCompare

[ Source](https://github.com/atk4/login)[ Packagist](https://packagist.org/packages/atk4/login)[ Docs](https://github.com/atk4/login)[ RSS](/packages/atk4-login/feed)WikiDiscussions develop Synced 3w ago

READMEChangelog (10)Dependencies (11)Versions (18)Used By (5)

[ATK UI](https://github.com/atk4/ui) implements a high-level User Interface for Web App - such as **Admin System**. One of the most common things for the Admin system is a log-in screen.

Although you can implement log-in form easily, this add-on does everything for you:

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

[](#installation)

Install through composer `composer require atk4/login`

Then add `Auth` into your app and set appropriate user controller:

```
$app = new \Atk4\Ui\App();
$app->initLayout([\Atk4\Ui\Layout\Admin::class]);
$app->db = new \Atk4\Data\Persistence($dsn);

// ADD THIS CODE:
$app->auth = new \Atk4\Login\Auth($app);
$app->auth->setModel(new \Atk4\Login\Model\User($app->db));

// The rest of YOUR UI code will now be protected
\Atk4\Ui\Crud::addTo($app)->setModel(new Client($app->db));
```

(If you do not have User model yet, you can extend or use \\Atk4\\Login\\Model\\User).

[![Login](./docs/login-form.png)](./docs/login-form.png)

Features
--------

[](#features)

Here are all the classes implemented:

- Full transparent authentication
    - Populates user menu with name of current user
    - Adds log-out link
    - Adds Preferences page
- Flexible ACL support
- Model\\User - basic user entity that can be extended
- LoginForm - username/password login form
- RegisterForm - registration form
- Auth - authentication controller, verify and record logged state
- UserAdmin - UI for user administration
- Layout\\Narrow - Fomantic-UI based narrow responsive layout login/registration forms
- Templates for forms an messages
- Demos for all of the above

When used default installation, it will relay on various other components (such as LoginForm), however you can also use those components individually.

Advanced Usage
--------------

[](#advanced-usage)

There are two modes of operation - Automated and Manual. Automated handles display of forms based on currently logged state automatically. It was already presented in the "Installation" section above.

For a more advanced usage, you can either tweak Automated mode or use individual components manually.

### Tweaking Automated Mode

[](#tweaking-automated-mode)

When you initialize 'Auth' class you may inject property values:

```
$app->auth = new \Atk4\Login\Auth($app, [
    'hasPreferences' => false, // do not show Preferences page/form
    'pageDashboard' => 'dashboard', // name of the page, where user arrives after login
    'pageExit' => 'goodbye', // where to send user after logout

    // Oter options:
    // 'hasUserMenu' => false, // will disable interaction with Admin Layout user menu
]);
$app->auth->setModel(new User($app->db));
```

### Using Manual Mode

[](#using-manual-mode)

In the manual mode, no checks will be performed, and you are responsible for authenticating user yourself. This works best if you have a more complex auth logic.

```
$app->auth = new \Atk4\Login\Auth($app, [
    'check' => false,
]);
$app->auth->setModel(new User($app->db));

// Now manually use login logic
if (!$app->auth->user->isLoaded()) {
    \Atk4\Login\LoginForm::addTo($app, ['auth' => $app->auth]);
}
```

#### Adding sign-up form

[](#adding-sign-up-form)

```
\Atk4\Login\RegisterForm::addTo($app)
    ->setEntity(new \Atk4\Login\Model\User($app->db));
```

Displays email and 2 password fields (for confirmation). If filled successfully will create new record for `\Atk4\Login\Model\User`. Will cast email to lowercase before adding. Things to try:

- Extend or use your own User class
- Add more fields to registration form
- Decorate registration form with message and links
- Use multi-column form layout

#### Log-in form

[](#log-in-form)

[![Login](./docs/login-form.png)](./docs/login-form.png)

```
\Atk4\Login\LoginForm::addTo($app, [
    'auth' => $app->auth,
    // 'successLink' => ['dashboard'],
    // 'forgotLink' => ['forgot'],
]);
```

Displays log-in form and associate it with $auth. When form is filled, will attempt to authenticate using $auth's model. If password is typed correctly, will redirect to "successLink" (which will be passed to $app-&gt;url()). Things to try:

- Redirect to login page if not authenticated
- Add 3rd party authentication (authenticate using 3rd party lib, look up connected account, store into auth persistence)
- Implement two factor authentication (store flag in auth persistence indicating if 2nd factor is carried out, if not display it)
- Implement password verification delay after several unsuccessful attempts
- Ask user to change password if it is about to expire

#### Dashboard

[](#dashboard)

To check if user is currently logged in:

```
if ($app->auth->user->isLoaded()) {
    // logged-in
}
```

Auth model stores user model data in session, so if you delete user from database, he will not be automatically logged out. To log-out user explicitly, call `$app->auth->logout()`.

You may also access user data like this: `$app->auth->model['name']`; Things to try:

- Explicitly load user record from database instead of cache only
- Store last login / last access time in database
- Move auth cache to MemCache

#### Profile Form

[](#profile-form)

This form would allow user to change user data (including password) but only if user is authenticated. To implement profile form use:

```
Form::addTo($app)->setEntity($app->auth->user);
```

Demos open profile form in a pop-up window, if you wish to do it, you can use this code:

```
Button::addTo($app, ['Profile', 'class.primary' => true])
    ->on('click', Modal::addTo($app)->set(function (View $p) {
        Form::addTo($p)->setEntity($p->getApp()->auth->user);
    })->jsShow());
```

Things to try:

- Ask user to verify old password before changing settings
- Send SMS notification / email if any user setting has bees changed
- Store user settings in multiple tables (join)

#### Password

[](#password)

Field 'password' is using a custom field class `Password`. Stored value is always a hash, use `Password::hashPassword()` + `Password::set()` methods to set the value or use `Password::setPassword()` method to set the password directly. You can use this field in any model like this:

```
$model->addField('password', [\Atk4\Data\Field\PasswordField::class]);
```

Also the password will not be stored in session cache and will not be accessible directly.

Things to try:

- Add complexity validation
- Add password recovery form
- use CAPCHA when recovering password

#### Custom User Model

[](#custom-user-model)

Although a basic User model is supplied, you can either extend it or use your own user model.

#### User Admin

[](#user-admin)

We include a slightly extended "Admin" interface which includes page to see user details and change their password. To create admin page use:

```
\Atk4\Login\UserAdmin::addTo($app)
    ->setModel(new \Atk4\Login\Model\User($app->db));
```

[![Login](./docs/admin-demo.png)](./docs/admin-demo.png)

This uses a standard CRUD interface, enhancing it with additional actions:

- key button allows to change user password and offers random password generator. Uses "input" field for a visible password. You can also use regular "edit" button which will contain asterisk-protected field for the password.
- eye button is designed to show user details, such as which group he belongs to. Currently this panel and groups are not implemented.

[![Login](./docs/change-password.png)](./docs/change-password.png)

Things to try:

- Add additional information on details modal.
- Add audit log for user actions (login, change password etc)

#### Migrations

[](#migrations)

Use of migration is optional, but can help by populating initial structure of your user model. Look inside file `demos/wizard.php`. It simply adds a console component, which will execute migration of 'User' model.

When migration is executed it simply checks to make sure that table for 'user' exists and has all required fields. It will not delete or change existing fields or tables.

Roadmap
-------

[](#roadmap)

Generally we wish to keep this add-on clean, but very extensible, with various tutorials on how to implement various scenarios (noted above under "Things to try").

For some of those features we would like to add a better support in next releases:

- \[1.0\] - add "$auth-&gt;check()" - for Automated authentication checks
- \[1.1\] - add Password Reminder form and tutorial on integration with Email / SMS sending
- \[1.2\] - add Password strength verification (and indicator)

If you would like to propose other features, please suggest them by opening ticket here:

-

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance65

Regular maintenance activity

Popularity34

Limited adoption so far

Community30

Small or concentrated contributor base

Maturity89

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~380 days

Total

16

Last Release

189d ago

Major Versions

0.9.0 → 1.0.02018-04-06

1.1.0 → 2.0.02020-01-20

2.4.0 → 3.0.02021-10-16

3.1.0 → 5.0.02024-03-26

5.0.0 → 6.0.02025-12-17

PHP version history (6 changes)0.9.0PHP &gt;=5.6.0

1.1.0PHP &gt;=7.2.0

2.2.0PHP &gt;=7.3.0

3.0.0PHP &gt;=7.4 &lt;8.2

5.0.0PHP &gt;=7.4 &lt;8.4

6.0.0PHP &gt;=7.4 &lt;8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/426ad318d07e7685454f7e449a9d0c9f005b83aef0777558d97d854ff9c28a5a?d=identicon)[romaninsh](/maintainers/romaninsh)

---

Top Contributors

[![DarkSide666](https://avatars.githubusercontent.com/u/1969119?v=4)](https://github.com/DarkSide666 "DarkSide666 (82 commits)")[![romaninsh](https://avatars.githubusercontent.com/u/453929?v=4)](https://github.com/romaninsh "romaninsh (46 commits)")[![mvorisek](https://avatars.githubusercontent.com/u/2228672?v=4)](https://github.com/mvorisek "mvorisek (22 commits)")[![abbadon1334](https://avatars.githubusercontent.com/u/5801824?v=4)](https://github.com/abbadon1334 "abbadon1334 (5 commits)")[![mkrecek234](https://avatars.githubusercontent.com/u/28671486?v=4)](https://github.com/mkrecek234 "mkrecek234 (5 commits)")[![acicovic](https://avatars.githubusercontent.com/u/23142906?v=4)](https://github.com/acicovic "acicovic (4 commits)")[![ibelar](https://avatars.githubusercontent.com/u/2204478?v=4)](https://github.com/ibelar "ibelar (3 commits)")[![gowrav-vishwakarma](https://avatars.githubusercontent.com/u/1007955?v=4)](https://github.com/gowrav-vishwakarma "gowrav-vishwakarma (3 commits)")[![karakal](https://avatars.githubusercontent.com/u/2448293?v=4)](https://github.com/karakal "karakal (3 commits)")[![PhilippGrashoff](https://avatars.githubusercontent.com/u/33204878?v=4)](https://github.com/PhilippGrashoff "PhilippGrashoff (2 commits)")[![FabulousGee](https://avatars.githubusercontent.com/u/30511025?v=4)](https://github.com/FabulousGee "FabulousGee (2 commits)")[![georgehristov](https://avatars.githubusercontent.com/u/8128250?v=4)](https://github.com/georgehristov "georgehristov (1 commits)")[![webbird](https://avatars.githubusercontent.com/u/147354?v=4)](https://github.com/webbird "webbird (1 commits)")

---

Tags

agileatk4authenticationloginphpframeworkdataauthuserAgileaclloginatk4agile ui

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/atk4-login/health.svg)

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

###  Alternatives

[atk4/mastercrud

Multi-level CRUD system component for ATK UI

109.7k](/packages/atk4-mastercrud)[atk4/chart

Chart.js for Agile UI

1214.2k](/packages/atk4-chart)[jsdecena/laravel-passport-multiauth

Simple laravel passport multiple user authentication

501.1k](/packages/jsdecena-laravel-passport-multiauth)[atk4/api

Agile API - Extensible API server in PHP for Agile Data

143.7k1](/packages/atk4-api)

PHPackages © 2026

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