From 02990169dfec2c638533eb7b7d3165453fba362d Mon Sep 17 00:00:00 2001 From: stellaljung Date: Mon, 11 Dec 2023 15:30:04 -0500 Subject: [PATCH] refactor: determine the table_num in less lines of code --- backend/src/server.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/backend/src/server.cpp b/backend/src/server.cpp index de242e9..023aaa9 100644 --- a/backend/src/server.cpp +++ b/backend/src/server.cpp @@ -32,15 +32,13 @@ namespace server return std::string(reinterpret_cast(sqlite3_column_text(stmt, 0))); }; - // get the table corresponding to the leaked byte + // get the table num corresponding to the user password leaked byte std::string decoded_password = crow::utility::base64decode(user_password, user_password.size()); - std::string encoded_byte = crow::utility::base64encode(decoded_password.substr(0, offset), offset); + std::string encoded_leaked_byte = crow::utility::base64encode(decoded_password.substr(0, offset), offset); + std::string table_num = "table" + std::to_string(static_cast(encoded_leaked_byte[0])); - int table_num = static_cast(encoded_byte[0]); - std::string table_str = std::to_string(table_num); - std::string query_str = "table" + table_str; - - std::vector breached_passwords = db.execute("SELECT * FROM " + query_str + ";", callback); + // get all passwords from the table corresponding to the user password leaked byte + std::vector breached_passwords = db.execute("SELECT * FROM " + table_num + ";", callback); // get b secret key from database std::string encoded_b = db.execute("SELECT * FROM secret;", callback)[0];