PHP code example of gobline / auth

1. Go to this page and download the library: Download gobline/auth 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/ */

    

gobline / auth example snippets


$user = new Gobline\Auth\CurrentUser();

use Gobline\Auth\Authenticator\Db\TableMetadata;
use Gobline\Auth\Authenticator\Db\DbAuthenticator;

$authenticator = new DbAuthenticator($pdo, new TableMetadata('users'));

use Gobline\Auth\Authenticator\Db\TableMetadata;
use Gobline\Auth\Authenticator\Db\DbAuthenticator;

$metadata = new TableMetadata('users');
$metadata
    ->setColumnId('user_id')
    ->setColumnLogin('user_email')
    ->setColumnRole('user_type')
    ->setColumnPassword('user_password')
    ->setPasswordEncryption('md5');

$authenticator = new DbAuthenticator($pdo, $metadata);

$authenticator->setIdentity('[email protected]');
$authenticator->setCredential('123456');

$user->isAuthenticated(); // returns false

if ($authenticator->authenticate($user)) {
	echo $user->getId(); // prints the user id from DB

	$user->isAuthenticated(); // returns true
}

$user = new Gobline\Auth\CurrentUser();
$user = new Gobline\Auth\Persistence\CurrentUser($user);