1. Go to this page and download the library: Download echo-fusion/authmanager 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/ */
use EchoFusion\AuthManager\AuthManager;
$auth = new AuthManager($container, $config); // $container: any PSR-11 container, see "Requirements of the container"
$web = $auth->statefulGuard('web');
if ($web->attempt(['email' => $email, 'password' => $password])) {
// logged in: the session id was regenerated and the user id stored
}
$web->check(); // bool
$web->guest(); // bool
$web->id(); // the user id, or null
$web->user(); // UserInterface or null
$web->logout();
$web->login($user); // log a user in without checking a password (e.g. right after registration)
$api = $auth->guard('api'); // reads the token from the request, so give it one:
$api->setRequest($request); // the middleware below does this for you
$api->user();
$token = bin2hex(random_bytes(32));
$connection->execute('UPDATE users SET api_token = ? WHERE id = ?', [hash('sha256', $token), $userId]);
// give $token to the client once; it cannot be recovered from the database
use EchoFusion\AuthManager\Middleware\AuthenticateMiddleware;
use EchoFusion\AuthManager\Middleware\GuestMiddleware;
new AuthenticateMiddleware($auth, $responseFactory, 'web', '/login'); // guard name, redirect target
new GuestMiddleware($auth, $responseFactory, 'web', '/');
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.