1. Go to this page and download the library: Download scafera/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/ */
use Scafera\Auth\Authenticator;
use Scafera\Auth\Password;
// Login
$user = $userProvider->findByIdentifier($email);
if ($user && $password->verify($user->getPassword(), $plainPassword)) {
$authenticator->login($user);
}
// Check
$authenticator->isAuthenticated(); // true
$authenticator->getUser(); // User instance
// Logout
$authenticator->logout();
// Rehash check (on login)
if ($password->needsRehash($user->getPassword())) {
// update stored hash
}
use Scafera\Auth\User;
use Scafera\Auth\UserProvider;
final class AppUser implements User
{
public function getIdentifier(): string;
public function getRoles(): array;
public function getPassword(): string;
}
final class AppUserProvider implements UserProvider
{
public function findByIdentifier(string $identifier): ?User;
}
use Scafera\Auth\Protect;
use Scafera\Auth\SessionGuard;
use Scafera\Auth\RoleGuard;
#[Protect(guard: SessionGuard::class)]
final class EditProfile
{
// Only authenticated users reach this controller
}
#[Protect(guard: RoleGuard::class, options: ['role' => 'ADMIN'])]
final class AdminDashboard
{
// Only users with ADMIN role
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.