Store password hash instead of plaintext for login persistence

Save SHA1(UPPER(user):UPPER(pass)) hash to login.cfg instead of the
plaintext password. On subsequent logins, use the stored hash directly
with a new authenticateWithHash() method that bypasses password hashing.
The password field shows a placeholder when using a stored hash.
This commit is contained in:
Kelsi 2026-02-05 15:09:16 -08:00
parent 45466f3d11
commit ca84384402
6 changed files with 107 additions and 4 deletions

View file

@ -93,6 +93,32 @@ void AuthHandler::authenticate(const std::string& user, const std::string& pass)
sendLogonChallenge();
}
void AuthHandler::authenticateWithHash(const std::string& user, const std::vector<uint8_t>& authHash) {
if (!isConnected()) {
LOG_ERROR("Cannot authenticate: not connected to auth server");
fail("Not connected");
return;
}
if (state != AuthState::CONNECTED) {
LOG_ERROR("Cannot authenticate: invalid state");
fail("Invalid state");
return;
}
LOG_INFO("Starting authentication for user (with hash): ", user);
username = user;
password.clear();
// Initialize SRP with pre-computed hash
srp = std::make_unique<SRP>();
srp->initializeWithHash(username, authHash);
// Send LOGON_CHALLENGE
sendLogonChallenge();
}
void AuthHandler::sendLogonChallenge() {
LOG_DEBUG("Sending LOGON_CHALLENGE");

View file

@ -19,11 +19,23 @@ void SRP::initialize(const std::string& username, const std::string& password) {
// Store credentials for later use
stored_username = username;
stored_password = password;
stored_auth_hash.clear();
initialized = true;
LOG_DEBUG("SRP initialized");
}
void SRP::initializeWithHash(const std::string& username, const std::vector<uint8_t>& authHash) {
LOG_DEBUG("Initializing SRP with username and pre-computed hash: ", username);
stored_username = username;
stored_password.clear();
stored_auth_hash = authHash;
initialized = true;
LOG_DEBUG("SRP initialized with hash");
}
void SRP::feed(const std::vector<uint8_t>& B_bytes,
const std::vector<uint8_t>& g_bytes,
const std::vector<uint8_t>& N_bytes,
@ -50,8 +62,10 @@ void SRP::feed(const std::vector<uint8_t>& B_bytes,
// Now compute everything in sequence
// 1. Compute auth hash: H(I:P)
std::vector<uint8_t> auth_hash = computeAuthHash(stored_username, stored_password);
// 1. Compute auth hash: H(I:P) — use stored hash if available
std::vector<uint8_t> auth_hash = stored_auth_hash.empty()
? computeAuthHash(stored_username, stored_password)
: stored_auth_hash;
// 2. Compute x = H(s | H(I:P))
std::vector<uint8_t> x_input;