PHPackages                             pieceofcake2/authenticate - 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. pieceofcake2/authenticate

ActiveCakephp-plugin[Authentication &amp; Authorization](/categories/authentication)

pieceofcake2/authenticate
=========================

CakePHP plugin with authentication classes for AuthComponent.

v1.0.3(7mo ago)00MITPHPPHP ^8.0CI passing

Since Oct 7Pushed 7mo agoCompare

[ Source](https://github.com/pieceofcake2/authenticate)[ Packagist](https://packagist.org/packages/pieceofcake2/authenticate)[ RSS](/packages/pieceofcake2-authenticate/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

Authenticate plugin
===================

[](#authenticate-plugin)

[![GitHub License](https://camo.githubusercontent.com/29cda96c90df637e5087d1b78a2f06971adb457637a947698643da06489e0028/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70696563656f6663616b65322f61757468656e7469636174653f6c6162656c3d4c6963656e7365)](LICENSE)[![Packagist Version](https://camo.githubusercontent.com/16f53a760121807c21e439544afaa9271721d04b2c7f09f2b460d6f8f380d6b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70696563656f6663616b65322f61757468656e7469636174653f6c6162656c3d5061636b6167697374)](https://packagist.org/packages/pieceofcake2/authenticate)[![PHP](https://camo.githubusercontent.com/ac0c970baad23cb64b04fc689dea72de89e72f2bbb6c4960be7acd5de2787b26/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f70696563656f6663616b65322f61757468656e7469636174652f7068703f6c6f676f3d706870266c6f676f436f6c6f723d253233464646464646266c6162656c3d504850266c6162656c436f6c6f723d25323337373742423426636f6c6f723d253233464646464646)](https://camo.githubusercontent.com/ac0c970baad23cb64b04fc689dea72de89e72f2bbb6c4960be7acd5de2787b26/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f70696563656f6663616b65322f61757468656e7469636174652f7068703f6c6f676f3d706870266c6f676f436f6c6f723d253233464646464646266c6162656c3d504850266c6162656c436f6c6f723d25323337373742423426636f6c6f723d253233464646464646)[![CakePHP](https://camo.githubusercontent.com/5cf79630a57894b347a01d31fa31a48ff5c35539e964170e12d5250da1627d0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f70696563656f6663616b65322f61757468656e7469636174652f70696563656f6663616b65322f63616b657068703f6c6f676f3d63616b65706870266c6f676f436f6c6f723d253233464646464646266c6162656c3d43616b65504850266c6162656c436f6c6f723d25323344333343343326636f6c6f723d253233464646464646)](https://camo.githubusercontent.com/5cf79630a57894b347a01d31fa31a48ff5c35539e964170e12d5250da1627d0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f70696563656f6663616b65322f61757468656e7469636174652f70696563656f6663616b65322f63616b657068703f6c6f676f3d63616b65706870266c6f676f436f6c6f723d253233464646464646266c6162656c3d43616b65504850266c6162656c436f6c6f723d25323344333343343326636f6c6f723d253233464646464646)[![CI](https://camo.githubusercontent.com/6ed0ba0d2eef93863cc0a552f6a07af8dff794052c5eb1f81cabb2b847792c34/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70696563656f6663616b65322f61757468656e7469636174652f43492e796d6c3f6c6162656c3d4349)](https://github.com/pieceofcake2/authenticate/actions/workflows/CI.yml)[![Codecov](https://camo.githubusercontent.com/0a74bdd67f4644e38705e32e1ac116e95b4ced796d7feff06ba8c62752eff838/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f70696563656f6663616b65322f61757468656e7469636174653f6c6162656c3d436f766572616765)](https://codecov.io/gh/pieceofcake2/authenticate)

**This is forked for CakePHP2.**

Plugin containing some authenticate classes for AuthComponent.

Current classes:

- MultiColumnAuthenticate, allow login with multiple db columns in single username field For example username or email
- CookieAuthenticate, login with a cookie
- TokenAuthenticate, login with a token as url parameter or header

GoogleAuthenticate is moved to separate repo:

Requirements
------------

[](#requirements)

- PHP 8.0+
- CakePHP 2.10+

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

[](#installation)

run: `composer require pieceofcake2/authenticate`

Usage
-----

[](#usage)

In `app/Config/bootstrap.php` add: `CakePlugin::load('Authenticate')`;

Configuration:
--------------

[](#configuration)

Setup the authentication class settings

### MultiColumnAuthenticate:

[](#multicolumnauthenticate)

```
    //in $components
    public $components = [
        'Auth' => [
            'authenticate' => [
                'Authenticate.MultiColumn' => [
                    'fields' => [
                        'username' => 'login',
                        'password' => 'password'
                    ],
                    'columns' => ['username', 'email'],
                    'userModel' => 'User',
                    'scope' => ['User.active' => 1],
                ]
            ]
        ]
    ];

    //Or in beforeFilter()
    $this->Auth->authenticate = [
        'Authenticate.MultiColumn' => [
            'fields' => [
                'username' => 'login',
                'password' => 'password'
            ],
            'columns' => ['username', 'email'],
            'userModel' => 'User',
            'scope' => ['User.active' => 1],
        ]
    ];
```

### CookieAuthenticate:

[](#cookieauthenticate)

```
    //in $components
    public $components = [
        'Auth' => [
            'authenticate' => [
                'Authenticate.Cookie' => [
                    'fields' => [
                        'username' => 'login',
                        'password' => 'password'
                    ],
                    'userModel' => 'SomePlugin.User',
                    'scope' => ['User.active' => 1],
                ]
            ]
        ]
    ];

    //Or in beforeFilter()
    $this->Auth->authenticate = [
        'Authenticate.Cookie' => [
            'fields' => [
                'username' => 'login',
                'password' => 'password'
            ],
            'userModel' => 'SomePlugin.User',
            'scope' => ['User.active' => 1],
        ]
    ];
```

### Setup both:

[](#setup-both)

It will first try to read the cookie, if that fails will try with form data:

```
    //in $components
    public $components = [
        'Auth' => [
            'authenticate' => [
                'Authenticate.Cookie' => [
                    'fields' => [
                        'username' => 'login',
                        'password' => 'password'
                    ],
                    'userModel' => 'SomePlugin.User',
                    'scope' => ['User.active' => 1],
                ],
                'Authenticate.MultiColumn' => [
                    'fields' => [
                        'username' => 'login',
                        'password' => 'password'
                    ],
                    'columns' => ['username', 'email'],
                    'userModel' => 'User',
                    'scope' => ['User.active' => 1],
                ]
            ]
        ]
    ];
```

### Security

[](#security)

For enhanced security, make sure you add this code to your `AppController::beforeFilter()` if you intend to use Cookie authentication:

```
public function beforeFilter() {
  $this->Cookie->type('rijndael'); //Enable AES symetric encryption of cookie
}
```

### Setting the cookie

[](#setting-the-cookie)

Example for setting the cookie:

```
