zero hash data

This commit is contained in:
sfja 2025-03-22 01:58:54 +01:00
parent 07667d0be4
commit 9b8bf7f46f
3 changed files with 4 additions and 3 deletions

View File

@ -29,7 +29,7 @@ void route_post_sessions_login(HttpCtx* ctx)
User user; User user;
DbRes db_res = db_user_with_email(cx->db, &user, req.email); DbRes db_res = db_user_with_email(cx->db, &user, req.email);
if (db_res == DbRes_NotFound) { if (db_res == DbRes_NotFound) {
RESPOND_BAD_REQUEST(ctx, "user with email not found"); RESPOND_BAD_REQUEST(ctx, "incorrect email or password");
goto l0_return; goto l0_return;
} else if (db_res == DbRes_Error) { } else if (db_res == DbRes_Error) {
RESPOND_SERVER_ERROR(ctx); RESPOND_SERVER_ERROR(ctx);
@ -37,7 +37,7 @@ void route_post_sessions_login(HttpCtx* ctx)
} }
if (!str_hash_equal(user.password_hash, req.password)) { if (!str_hash_equal(user.password_hash, req.password)) {
RESPOND_BAD_REQUEST(ctx, "wrong password"); RESPOND_BAD_REQUEST(ctx, "incorrect email or password");
goto l2_return; goto l2_return;
} }

View File

@ -149,7 +149,7 @@ static inline HashData hashdata_from_str_and_salt(
memcpy(data.salt, salt, STR_HASH_SALT_SIZE); memcpy(data.salt, salt, STR_HASH_SALT_SIZE);
size_t input_size = MAX_HASH_INPUT_LEN + str_length; size_t input_size = MAX_HASH_INPUT_LEN + str_length;
uint8_t* input_data = malloc(input_size); uint8_t* input_data = calloc(input_size, 1);
memcpy(input_data, data.salt, STR_HASH_SALT_SIZE); memcpy(input_data, data.salt, STR_HASH_SALT_SIZE);
memcpy(&input_data[STR_HASH_SALT_SIZE], str, str_length); memcpy(&input_data[STR_HASH_SALT_SIZE], str, str_length);

View File

@ -26,6 +26,7 @@ Deno.test("test backend", async (t) => {
{ email, password }, { email, password },
); );
//console.log(loginRes);
assertEquals(loginRes.ok, true); assertEquals(loginRes.ok, true);
assertMatch(loginRes.token, /^[0-9a-zA-Z]+$/); assertMatch(loginRes.token, /^[0-9a-zA-Z]+$/);
token = loginRes.token; token = loginRes.token;