Manages authentication and session handling for Wavelength frequencies using a singleton pattern.
More...
#include <authentication_manager.h>
|
| void | CleanupExpiredSessions () |
| | Removes session information for sessions older than 24 hours.
|
| |
| void | DeactivateClientSessions (const QString &client_id) |
| | Marks all sessions associated with a specific client ID as inactive.
|
| |
| void | DeactivateFrequencySessions (const QString &frequency) |
| | Marks all sessions associated with a specific frequency as inactive.
|
| |
| void | DeactivateSession (const QString &session_token) |
| | Marks a specific session as inactive.
|
| |
| void | RegisterPassword (const QString &frequency, const QString &password) |
| | Registers or updates the password for a specific frequency.
|
| |
| void | RemovePassword (const QString &frequency) |
| | Removes the password associated with a specific frequency.
|
| |
| bool | StoreSession (const QString &frequency, const QString &client_id, const QString &session_token) |
| | Stores information about a newly established client session.
|
| |
| bool | ValidateSession (const QString &session_token, const QString &frequency) |
| | Validates an existing session token for a specific frequency. Checks if the token exists, belongs to the correct frequency, is active, and has not expired (24h validity).
|
| |
| bool | VerifyPassword (const QString &frequency, const QString &provided_password) |
| | Verifies if the provided password matches the stored password for a given frequency.
|
| |
|
| static QString | CreateAuthResponse (bool success, const QString &error_message=QString()) |
| | Creates a JSON response string indicating the result of an authentication attempt. Includes a session token if authentication was successful.
|
| |
| static QString | GenerateClientId () |
| | Generates a unique client identifier.
|
| |
| static QString | GenerateSessionToken () |
| | Generates a cryptographically secure session token. Uses a combination of UUID and timestamp, hashed with SHA256.
|
| |
| static AuthenticationManager * | GetInstance () |
| | Gets the singleton instance of the AuthenticationManager.
|
| |
|
| QMap< QString, SessionInfo > | sessions_ {} |
| | Map storing active session information. Key: Session token (QString). Value: SessionInfo struct containing details about the session.
|
| |
| QMap< QString, QString > | wavelength_passwords_ {} |
| | Map storing salted and hashed passwords associated with frequencies. Key: Frequency identifier (QString). Value: QString in the format "salt_hex$hashed_password_hex".
|
| |
Manages authentication and session handling for Wavelength frequencies using a singleton pattern.
This class is responsible for:
- Generating unique client IDs and session tokens.
- Registering and verifying passwords associated with specific frequencies.
- Creating authentication response messages (JSON).
- Storing, validating, and managing active client sessions.
- Deactivating sessions based on token, client ID, or frequency.
- Cleaning up expired sessions.
◆ AuthenticationManager() [1/2]
| AuthenticationManager::AuthenticationManager |
( |
QObject * | parent = nullptr | ) |
|
|
inlineexplicitprivate |
Private constructor to enforce the singleton pattern.
- Parameters
-
| parent | Optional parent QObject. |
◆ ~AuthenticationManager()
| AuthenticationManager::~AuthenticationManager |
( |
| ) |
|
|
overrideprivatedefault |
◆ AuthenticationManager() [2/2]
Deleted copy constructor to prevent copying.
◆ CleanupExpiredSessions()
| void AuthenticationManager::CleanupExpiredSessions |
( |
| ) |
|
Removes session information for sessions older than 24 hours.
◆ CreateAuthResponse()
| QString AuthenticationManager::CreateAuthResponse |
( |
bool | success, |
|
|
const QString & | error_message = QString() ) |
|
static |
Creates a JSON response string indicating the result of an authentication attempt. Includes a session token if authentication was successful.
- Parameters
-
| success | True if authentication was successful, false otherwise. |
| error_message | An optional error message to include if authentication failed. |
- Returns
- A compact JSON string representing the authentication result.
◆ DeactivateClientSessions()
| void AuthenticationManager::DeactivateClientSessions |
( |
const QString & | client_id | ) |
|
Marks all sessions associated with a specific client ID as inactive.
- Parameters
-
| client_id | The ID of the client whose sessions should be deactivated. |
◆ DeactivateFrequencySessions()
| void AuthenticationManager::DeactivateFrequencySessions |
( |
const QString & | frequency | ) |
|
Marks all sessions associated with a specific frequency as inactive.
- Parameters
-
| frequency | The frequency identifier whose sessions should be deactivated. |
◆ DeactivateSession()
| void AuthenticationManager::DeactivateSession |
( |
const QString & | session_token | ) |
|
Marks a specific session as inactive.
- Parameters
-
| session_token | The token of the session to deactivate. |
◆ GenerateClientId()
| QString AuthenticationManager::GenerateClientId |
( |
| ) |
|
|
static |
Generates a unique client identifier.
- Returns
- A unique client ID as a QString (UUID without braces).
◆ GenerateSessionToken()
| QString AuthenticationManager::GenerateSessionToken |
( |
| ) |
|
|
static |
Generates a cryptographically secure session token. Uses a combination of UUID and timestamp, hashed with SHA256.
- Returns
- A unique session token as a hexadecimal QString.
◆ GetInstance()
◆ operator=()
Deleted assignment operator to prevent assignment.
◆ RegisterPassword()
| void AuthenticationManager::RegisterPassword |
( |
const QString & | frequency, |
|
|
const QString & | password ) |
Registers or updates the password for a specific frequency.
- Parameters
-
| frequency | The frequency identifier. |
| password | The password to associate with the frequency. |
◆ RemovePassword()
| void AuthenticationManager::RemovePassword |
( |
const QString & | frequency | ) |
|
Removes the password associated with a specific frequency.
- Parameters
-
| frequency | The frequency identifier whose password should be removed. |
◆ StoreSession()
| bool AuthenticationManager::StoreSession |
( |
const QString & | frequency, |
|
|
const QString & | client_id, |
|
|
const QString & | session_token ) |
Stores information about a newly established client session.
- Parameters
-
| frequency | The frequency the client connected to. |
| client_id | The unique ID of the client. |
| session_token | The unique token assigned to this session. |
- Returns
- True if the session was stored successfully (currently always returns true).
◆ ValidateSession()
| bool AuthenticationManager::ValidateSession |
( |
const QString & | session_token, |
|
|
const QString & | frequency ) |
Validates an existing session token for a specific frequency. Checks if the token exists, belongs to the correct frequency, is active, and has not expired (24h validity).
- Parameters
-
| session_token | The session token to validate. |
| frequency | The frequency the session should be associated with. |
- Returns
- True if the session is valid, false otherwise.
◆ VerifyPassword()
| bool AuthenticationManager::VerifyPassword |
( |
const QString & | frequency, |
|
|
const QString & | provided_password ) |
Verifies if the provided password matches the stored password for a given frequency.
- Parameters
-
| frequency | The frequency identifier. |
| provided_password | The password attempt provided by the client. |
- Returns
- True if the password is correct or if no password is set for the frequency, false otherwise.
◆ sessions_
| QMap<QString, SessionInfo> AuthenticationManager::sessions_ {} |
|
private |
Map storing active session information. Key: Session token (QString). Value: SessionInfo struct containing details about the session.
◆ wavelength_passwords_
| QMap<QString, QString> AuthenticationManager::wavelength_passwords_ {} |
|
private |
Map storing salted and hashed passwords associated with frequencies. Key: Frequency identifier (QString). Value: QString in the format "salt_hex$hashed_password_hex".
- Note
- Passwords are now stored salted and hashed for improved security.
The documentation for this class was generated from the following files: