1. Go to this page and download the library: Download jdz/authentication 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/ */
jdz / authentication example snippets
use JDZ\Authentication\Authentication;
use JDZ\Authentication\Connector\BasicConnector;
$auth = new Authentication();
$auth->addConnector(new BasicConnector('admin', 'secret123'));
$result = $auth->authenticate([
'identifier' => 'admin',
'password' => 'secret123',
]);
if ($result->isSuccess()) {
echo "Welcome, " . $result->getUsername();
} else {
echo "Error: " . $result->getMessage();
}
$result->isSuccess(); // bool - Check if authentication succeeded
$result->getStatus(); // AuthStatusEnum - Get the status enum
$result->getMessage(); // string - Get error message (or status message)
$result->getUserId(); // ?int - Get user ID (if available)
$result->getIdentifier(); // string - Get the identifier used
$result->getEmail(); // string - Get user email
$result->getUsername(); // string - Get username
$result->getFirstname(); // string - Get first name
$result->getLastname(); // string - Get last name
$result->getFullname(); // string - Get full name (or fallback to email/identifier)
$result->getType(); // string - Get connector type (e.g., "basic", "database")
$result->get($key); // mixed - Get custom data
$result->toArray(); // array - Convert to array
bash
php examples/01-basic-authentication.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.