Authentication
in package
implements
IAuthenticationService
Authentication service.
Handles user authentication, session management, and remember me functionality.
Table of Contents
Interfaces
- IAuthenticationService
- Authentication Service Interface
Properties
- $_lockoutDuration : int
- $_maxLoginAttempts : int
- $_passwordHasher : PasswordHasher
- $_sessionManager : SessionManager
- $_userRepository : IUserRepository
Methods
- __construct() : mixed
- attempt() : bool
- Attempt to authenticate a user
- check() : bool
- Check if a user is authenticated
- hasRole() : bool
- Check if user has a specific role
- id() : int|null
- Get the current user's ID
- isAdmin() : bool
- Check if user is admin
- isAuthorOrHigher() : bool
- Check if user is author or higher
- isEditorOrHigher() : bool
- Check if user is editor or higher
- login() : void
- Log a user in
- loginUsingRememberToken() : bool
- Attempt to log in using remember token
- logout() : void
- Log the current user out
- setLockoutDuration() : self
- Set lockout duration in minutes
- setMaxLoginAttempts() : self
- Set maximum login attempts before lockout
- user() : User|null
- Get the currently authenticated user
- validateCredentials() : bool
- Validate user credentials
- setRememberToken() : void
- Set remember me token for user
Properties
$_lockoutDuration
private
int
$_lockoutDuration
= 15
$_maxLoginAttempts
private
int
$_maxLoginAttempts
= 5
$_passwordHasher
private
PasswordHasher
$_passwordHasher
$_sessionManager
private
SessionManager
$_sessionManager
$_userRepository
private
IUserRepository
$_userRepository
Methods
__construct()
public
__construct(IUserRepository $userRepository, SessionManager $sessionManager, PasswordHasher $passwordHasher) : mixed
Parameters
- $userRepository : IUserRepository
- $sessionManager : SessionManager
- $passwordHasher : PasswordHasher
attempt()
Attempt to authenticate a user
public
attempt(string $username, string $password[, bool $remember = false ]) : bool
Parameters
- $username : string
- $password : string
- $remember : bool = false
Return values
bool —True if authentication successful
check()
Check if a user is authenticated
public
check() : bool
Return values
boolhasRole()
Check if user has a specific role
public
hasRole(string $role) : bool
Parameters
- $role : string
Return values
boolid()
Get the current user's ID
public
id() : int|null
Return values
int|nullisAdmin()
Check if user is admin
public
isAdmin() : bool
Return values
boolisAuthorOrHigher()
Check if user is author or higher
public
isAuthorOrHigher() : bool
Return values
boolisEditorOrHigher()
Check if user is editor or higher
public
isEditorOrHigher() : bool
Return values
boollogin()
Log a user in
public
login(User $user[, bool $remember = false ]) : void
Parameters
- $user : User
- $remember : bool = false
loginUsingRememberToken()
Attempt to log in using remember token
public
loginUsingRememberToken(string $token) : bool
Parameters
- $token : string
Return values
boollogout()
Log the current user out
public
logout() : void
setLockoutDuration()
Set lockout duration in minutes
public
setLockoutDuration(int $lockoutDuration) : self
Parameters
- $lockoutDuration : int
Return values
selfsetMaxLoginAttempts()
Set maximum login attempts before lockout
public
setMaxLoginAttempts(int $maxLoginAttempts) : self
Parameters
- $maxLoginAttempts : int
Return values
selfuser()
Get the currently authenticated user
public
user() : User|null
Return values
User|nullvalidateCredentials()
Validate user credentials
public
validateCredentials(User $user, string $password) : bool
Parameters
- $user : User
- $password : string
Return values
boolsetRememberToken()
Set remember me token for user
private
setRememberToken(User $user) : void
Parameters
- $user : User