Repository navigation
Internals Admin AdminAuthentication
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/admin/AdminAuthentication.php · Snapshot 8411f4287706.
Admin models and authentication manage the framework administrator record and PHP session. Permission levels are compared numerically with lower values granting broader access. Passwords currently use SHA-512.
use /**
* Class DatabaseManager
*
* Manages database connections, queries, and transactions. Provides
* functionality to interact with the database in a structured and
* organized manner.
*
* Responsibilities:
* - Establishing and managing connections to the database.
* - Executing database queries.
* - Managing transactions (commit, rollback).
* - Handling database errors and exceptions.
* - Providing utilities for prepared statements and parameter binding.
*/
database\DatabaseManager;
use /**
* Class SessionHandler
*
* Handles session management operations, including reading, writing, updating,
* and destroying session data. Implements session handling according to PHP's
* session handler interface to allow custom session storage.
*
* Responsibilities:
* - Read session data from the storage.
* - Write updated session data to the storage.
* - Delete session data upon session expiration or destruction.
* - Manage session lifecycle.
*
* Usage:
* This handler can be registered using session_set_save_handler() for
* custom session handling mechanisms.
*/
session\SessionHandler;final class AdminAuthentication extends SessionHandlerSource description (behavioral corrections are recorded in Known discrepancies):
Handles administrative authentication within the system.
The AdminAuthentication class extends the functionality of the SessionHandler class and is responsible for verifying administrator credentials and managing authenticated admin sessions.
Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.
| Member | Declaration | Purpose or source contract |
|---|---|---|
| $userName | private string $userName; |
Used by __construct(), authenticate(). |
| $password | private string $password; |
Used by __construct(), authenticate(). |
| $database | private DatabaseManager $database; |
Used by __construct(), authenticate(). |
| Constructor-promoted | public function __construct(string $userName |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Method | Signature |
|---|---|
| __construct | public function __construct(string $userName, string $password) |
| authenticate | public function authenticate(): bool |
public function __construct(string $userName, string $password)| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$userName |
string $userName |
The username of the administrator. |
$password |
string $password |
The password of the administrator. |
Constructor method for AdminAuthentication.
Initializes the userName and password properties and creates a new instance of DatabaseManager for database interactions.
@param string $userName The username of the administrator. @param string $password The password of the administrator.
State writes: $this->userName, $this->password, $this->database.
Implementation, validation guards and interaction order
/**
* Constructor method for AdminAuthentication.
*
* Initializes the userName and password properties and creates
* a new instance of DatabaseManager for database interactions.
*
* @param string $userName The username of the administrator.
* @param string $password The password of the administrator.
*/
public function __construct(string $userName, string $password)
{
$this->userName = $userName;
$this->password = $password;
$this->database = new DatabaseManager();
}public function authenticate(): boolAuthenticates the administrator by verifying the username and password against the database.
The method hashes the password using SHA-512 and checks for a matching record in the "awt_admin" table. If a match is found, it initializes the session and stores the admins information.
@return bool Returns true if authentication is successful, false otherwise.
Return expressions (including local callbacks): true; false.
Implementation, validation guards and interaction order
/**
* Authenticates the administrator by verifying the username and
* password against the database.
*
* The method hashes the password using SHA-512 and checks for a
* matching record in the "awt_admin" table. If a match is found,
* it initializes the session and stores the admins information.
*
* @return bool Returns true if authentication is successful,
* false otherwise.
*/
public function authenticate(): bool
{
$password_hash = hash('SHA512', $this->password);
$result = $this->database->table("awt_admin")
->select()
->where([
'username' => $this->userName,
'password' => $password_hash,
])
->get();
if(!empty($result)){
$this->SessionHandler();
$_SESSION['admin']['id'] = $result[0]['id'];
$_SESSION['admin']['username'] = $result[0]['username'];
$_SESSION['admin']['permission'] = $result[0]['permission_level'];
$_SESSION['admin']['token'] = $result[0]['token'];
$this->database->table("awt_admin")->where(["id" => $result[0]['id']])->update(["last_logged_ip" => $_SERVER['REMOTE_ADDR']]);
return true;
}
return false;
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes