Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
AuthenticationManager Class Referencefinal

Manages authentication and session handling for Wavelength frequencies using a singleton pattern. More...

#include <authentication_manager.h>

Inheritance diagram for AuthenticationManager:
Collaboration diagram for AuthenticationManager:

Classes

struct  SessionInfo
 Structure holding information about an active client session. More...
 

Public Member Functions

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 Public Member Functions

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 AuthenticationManagerGetInstance ()
 Gets the singleton instance of the AuthenticationManager.
 

Private Member Functions

 AuthenticationManager (const AuthenticationManager &)=delete
 Deleted copy constructor to prevent copying.
 
 AuthenticationManager (QObject *parent=nullptr)
 Private constructor to enforce the singleton pattern.
 
AuthenticationManageroperator= (const AuthenticationManager &)=delete
 Deleted assignment operator to prevent assignment.
 
 ~AuthenticationManager () override=default
 Private destructor.
 

Private Attributes

QMap< QString, SessionInfosessions_ {}
 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".
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ AuthenticationManager() [1/2]

AuthenticationManager::AuthenticationManager ( QObject * parent = nullptr)
inlineexplicitprivate

Private constructor to enforce the singleton pattern.

Parameters
parentOptional parent QObject.
Here is the caller graph for this function:

◆ ~AuthenticationManager()

AuthenticationManager::~AuthenticationManager ( )
overrideprivatedefault

Private destructor.

◆ AuthenticationManager() [2/2]

AuthenticationManager::AuthenticationManager ( const AuthenticationManager & )
privatedelete

Deleted copy constructor to prevent copying.

Here is the call graph for this function:

Member Function Documentation

◆ 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
successTrue if authentication was successful, false otherwise.
error_messageAn optional error message to include if authentication failed.
Returns
A compact JSON string representing the authentication result.
Here is the call graph for this function:

◆ DeactivateClientSessions()

void AuthenticationManager::DeactivateClientSessions ( const QString & client_id)

Marks all sessions associated with a specific client ID as inactive.

Parameters
client_idThe 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
frequencyThe frequency identifier whose sessions should be deactivated.

◆ DeactivateSession()

void AuthenticationManager::DeactivateSession ( const QString & session_token)

Marks a specific session as inactive.

Parameters
session_tokenThe 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).
Here is the caller graph for this function:

◆ 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.
Here is the caller graph for this function:

◆ GetInstance()

static AuthenticationManager * AuthenticationManager::GetInstance ( )
inlinestatic

Gets the singleton instance of the AuthenticationManager.

Returns
Pointer to the singleton AuthenticationManager instance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

AuthenticationManager & AuthenticationManager::operator= ( const AuthenticationManager & )
privatedelete

Deleted assignment operator to prevent assignment.

Here is the call graph for this function:

◆ RegisterPassword()

void AuthenticationManager::RegisterPassword ( const QString & frequency,
const QString & password )

Registers or updates the password for a specific frequency.

Parameters
frequencyThe frequency identifier.
passwordThe password to associate with the frequency.

◆ RemovePassword()

void AuthenticationManager::RemovePassword ( const QString & frequency)

Removes the password associated with a specific frequency.

Parameters
frequencyThe 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
frequencyThe frequency the client connected to.
client_idThe unique ID of the client.
session_tokenThe 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_tokenThe session token to validate.
frequencyThe 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
frequencyThe frequency identifier.
provided_passwordThe password attempt provided by the client.
Returns
True if the password is correct or if no password is set for the frequency, false otherwise.

Member Data Documentation

◆ 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: