38 lines
1.3 KiB
C++
38 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <LittleFS.h>
|
|
#include <webui.pb.h> // Ensure this is the version with 'bytes password_hash'
|
|
#include <functional> // Required for std::function
|
|
|
|
// This struct definition is correct and necessary.
|
|
struct UserData {
|
|
char username[33]; // 32 chars + null terminator
|
|
uint8_t password_hash[32]; // 32-byte raw SHA-256 hash
|
|
};
|
|
|
|
class Users {
|
|
public:
|
|
Users();
|
|
~Users();
|
|
|
|
bool addUser(const char* username, const char* password);
|
|
bool deleteUser(const char* username);
|
|
bool updatePassword(const char* username, const char* newPassword);
|
|
bool userExists(const char* username) const;
|
|
bool checkPassword(const char* username, const char* password) const;
|
|
bool loadUsernamesCallback(const std::function<bool(const char*)>& callback) const;
|
|
size_t getUserCount();
|
|
void reset();
|
|
|
|
private:
|
|
const char* filename_ = "/users.pb";
|
|
static constexpr size_t MAX_USERS = 5;
|
|
mutable size_t userCount_ = 0;
|
|
mutable bool initialized_ = false;
|
|
|
|
void hashPassword(const char* password, uint8_t* hash_out) const; static bool _iterateUsers(const char* filename, const std::function<bool(UserData&)>& user_callback);
|
|
static bool _transformUsers(const char* src_filename, const std::function<bool(UserData&)>& transform_callback);
|
|
};
|
|
|
|
|
|
extern Users users; |