Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
authentication_manager.h
Go to the documentation of this file.
1#ifndef AUTHENTICATION_MANAGER_H
2#define AUTHENTICATION_MANAGER_H
3
4#include <QDateTime>
5#include <QMap>
6#include <QObject>
7
19class AuthenticationManager final : public QObject {
20 Q_OBJECT
21
22public:
28 static AuthenticationManager instance;
29 return &instance;
30 }
31
36 static QString GenerateClientId();
37
43 static QString GenerateSessionToken();
44
50 void RegisterPassword(const QString &frequency, const QString &password);
51
58 bool VerifyPassword(const QString &frequency, const QString &provided_password);
59
64 void RemovePassword(const QString &frequency);
65
73 static QString CreateAuthResponse(bool success, const QString &error_message = QString());
74
82 bool StoreSession(const QString &frequency, const QString &client_id, const QString &session_token);
83
91 bool ValidateSession(const QString &session_token, const QString &frequency);
92
97 void DeactivateSession(const QString &session_token);
98
103 void DeactivateClientSessions(const QString &client_id);
104
109 void DeactivateFrequencySessions(const QString &frequency);
110
115
116private:
120 struct SessionInfo {
121 QString client_id;
122 QString frequency;
123 QDateTime timestamp;
125 };
126
131 explicit AuthenticationManager(QObject *parent = nullptr) : QObject(parent) {
132 }
133
137 ~AuthenticationManager() override = default;
138
143
148
155 QMap<QString, QString> wavelength_passwords_{};
156
162 QMap<QString, SessionInfo> sessions_{};
163};
164
165#endif // AUTHENTICATION_MANAGER_H
void DeactivateClientSessions(const QString &client_id)
Marks all sessions associated with a specific client ID as inactive.
Definition authentication_manager.cpp:132
static QString CreateAuthResponse(bool success, const QString &error_message=QString())
Creates a JSON response string indicating the result of an authentication attempt....
Definition authentication_manager.cpp:69
void CleanupExpiredSessions()
Removes session information for sessions older than 24 hours.
Definition authentication_manager.cpp:148
void RemovePassword(const QString &frequency)
Removes the password associated with a specific frequency.
Definition authentication_manager.cpp:63
AuthenticationManager(QObject *parent=nullptr)
Private constructor to enforce the singleton pattern.
Definition authentication_manager.h:131
QMap< QString, QString > wavelength_passwords_
Map storing salted and hashed passwords associated with frequencies. Key: Frequency identifier (QStri...
Definition authentication_manager.h:155
QMap< QString, SessionInfo > sessions_
Map storing active session information. Key: Session token (QString). Value: SessionInfo struct conta...
Definition authentication_manager.h:162
void RegisterPassword(const QString &frequency, const QString &password)
Registers or updates the password for a specific frequency.
Definition authentication_manager.cpp:18
AuthenticationManager & operator=(const AuthenticationManager &)=delete
Deleted assignment operator to prevent assignment.
void DeactivateFrequencySessions(const QString &frequency)
Marks all sessions associated with a specific frequency as inactive.
Definition authentication_manager.cpp:140
bool VerifyPassword(const QString &frequency, const QString &provided_password)
Verifies if the provided password matches the stored password for a given frequency.
Definition authentication_manager.cpp:31
static QString GenerateSessionToken()
Generates a cryptographically secure session token. Uses a combination of UUID and timestamp,...
Definition authentication_manager.cpp:12
static QString GenerateClientId()
Generates a unique client identifier.
Definition authentication_manager.cpp:8
bool StoreSession(const QString &frequency, const QString &client_id, const QString &session_token)
Stores information about a newly established client session.
Definition authentication_manager.cpp:85
~AuthenticationManager() override=default
Private destructor.
static AuthenticationManager * GetInstance()
Gets the singleton instance of the AuthenticationManager.
Definition authentication_manager.h:27
void DeactivateSession(const QString &session_token)
Marks a specific session as inactive.
Definition authentication_manager.cpp:126
AuthenticationManager(const AuthenticationManager &)=delete
Deleted copy constructor to prevent copying.
bool ValidateSession(const QString &session_token, const QString &frequency)
Validates an existing session token for a specific frequency. Checks if the token exists,...
Definition authentication_manager.cpp:98
Structure holding information about an active client session.
Definition authentication_manager.h:120
bool is_active
Flag indicating if the session is currently active.
Definition authentication_manager.h:124
QString frequency
The frequency the session is associated with.
Definition authentication_manager.h:122
QString client_id
Unique identifier of the client holding the session.
Definition authentication_manager.h:121
QDateTime timestamp
Timestamp when the session was created or last validated.
Definition authentication_manager.h:123