PHP code example of crabstudio / authenticate

1. Go to this page and download the library: Download crabstudio/authenticate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

crabstudio / authenticate example snippets


// All config key as usual FormAuthenticate/BaseAuthenticate
// I list the different config keys only.

$this->loadComponent('Auth', [
    'authenticate' => [
        'Authenticate.Advance' => [
	        'lockout' => [
	            'retries' => 3,
	            'expires' => '5 minutes',
	            'file_path' => 'prevent_brute_force',
	            'message' => [
	                'locked' => 'You have exceeded the number of allowed login attempts. Please try again in {0}',
	                'login_fail' => 'Incorrect username or password. {0} retries remain. Please try again',
	            ]
	        ],
	        'remember' => [
	            'enable' => true,
	            'key' => 'RememberMe',
	            'expires' => '1 months',
	        ],
        ],
    ]);

// remember to import Event to the AppController.php
use Cake\Event\Event;

public function initialize()
{
    parent::initialize();
    $this->loadComponent('Cookie');
}

public function beforeFilter(Event $event)
{
    //Automaticaly Login.
    if (!$this->Auth->user() && $this->Cookie->read('RememberMe')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
        } else {
            $this->Cookie->delete('RememberMe');
        }
    }
}

// login.ctp template

<?=$this->Form->create()