generated from scayac/esp32Webapp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
903 B
37 lines
903 B
#ifndef AUTH_H |
|
#define AUTH_H |
|
|
|
#include <Arduino.h> |
|
#include <map> |
|
|
|
struct Session { |
|
String username; |
|
unsigned long lastActivity; |
|
unsigned long timeout; // en millisecondes |
|
}; |
|
|
|
class AuthManager { |
|
private: |
|
String username; |
|
String passwordHash; |
|
std::map<String, Session> sessions; |
|
unsigned long sessionTimeout; // en minutes |
|
|
|
public: |
|
AuthManager(); |
|
void setCredentials(const String& user, const String& passHash); |
|
void setSessionTimeout(unsigned long timeout); |
|
|
|
bool authenticate(const String& user, const String& password); |
|
String createSession(const String& user); |
|
bool validateSession(const String& sessionId); |
|
void updateSessionActivity(const String& sessionId); |
|
void removeSession(const String& sessionId); |
|
void cleanExpiredSessions(); |
|
|
|
String getUsername() { return username; } |
|
}; |
|
|
|
extern AuthManager authManager; |
|
|
|
#endif
|
|
|