PHP code example of dmitrymomot / php-auth

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

    

dmitrymomot / php-auth example snippets


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

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

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

$auth->getRole() // returns string

$auth->loggedIn() // returned true

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

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

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

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

$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'
));

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

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

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

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

$auth->createUser(array('username' => 'test_user', 'password' => 'some_password', 'email' => '[email protected]', ...)); // returns boolean value or array error messages

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

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

\Auth\Auth::hashKey = 'vv34r3v4c34r';
json
{
    "mitrymomot/php-auth": "1.*"
    }
}
json
    "ymomot/php-session": "1.*",
        "php-activerecord/php-activerecord":"dev-master"
    },