From 634554a0df8dfd35630f17b5fee44c54b7af73a5 Mon Sep 17 00:00:00 2001 From: fusion32 Date: Fri, 1 Aug 2025 19:23:13 -0300 Subject: fix problem with concurrent writes + implement website queries There was a problem with concurrent writes not being visible until after restart, due to how cached prepared statements work with SQLite (see comment in `database.cc`). --- src/sha256.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/sha256.cc') diff --git a/src/sha256.cc b/src/sha256.cc index 1070c6b..9e2bb23 100644 --- a/src/sha256.cc +++ b/src/sha256.cc @@ -144,7 +144,24 @@ bool TestPassword(const uint8 *Auth, int AuthSize, const char *Password){ for(int i = 0; i < 32; i += 1){ Result |= Digest[i] ^ Hash[i]; } - return Result == 0;; + return Result == 0; +} + +bool GenerateAuth(const char *Password, uint8 *Auth, int AuthSize){ + if(AuthSize != 64){ + LOG_ERR("Expected 64 bytes buffer for authentication data (got %d)", AuthSize); + return false; + } + + uint8 *Hash = &Auth[ 0]; + uint8 *Salt = &Auth[32]; + CryptoRandom(Salt, 32); + SHA256((const uint8*)Password, (int)strlen(Password), Hash); + for(int i = 0; i < 32; i += 1){ + Hash[i] ^= Salt[i]; + } + SHA256(Hash, 32, Hash); + return true; } // CheckSHA256 -- cgit v1.2.3