implemented WHY2_CHAT_CODE_PASSWORD

This commit is contained in:
Václav Šmejkal 2025-02-01 21:03:49 +01:00
parent ee309b2cbb
commit a4b8bf2f4c
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 38 additions and 9 deletions

View File

@ -288,7 +288,7 @@ int main(void)
char *hash = why2_sha256(line, strlen(line)); //HASHISH char *hash = why2_sha256(line, strlen(line)); //HASHISH
why2_send_socket(hash, NULL, listen_socket); //SEND BUT HASHED why2_send_socket_code(hash, NULL, listen_socket, WHY2_CHAT_CODE_PASSWORD); //SEND BUT HASHED
//DEALLOCATION //DEALLOCATION
why2_deallocate(hash); why2_deallocate(hash);

View File

@ -572,6 +572,7 @@ void *why2_communicate_thread(void *arg)
code = get_string_from_json_string(raw, "code"); code = get_string_from_json_string(raw, "code");
exiting_read = code != NULL && strcmp(code, WHY2_CHAT_CODE_USERNAME) == 0; exiting_read = code != NULL && strcmp(code, WHY2_CHAT_CODE_USERNAME) == 0;
} while (!exiting_read); } while (!exiting_read);
why2_deallocate(code);
decoded_buffer = get_string_from_json_string(raw, "message"); //DECODE decoded_buffer = get_string_from_json_string(raw, "message"); //DECODE
@ -617,12 +618,26 @@ void *why2_communicate_thread(void *arg)
{ {
send_socket_code_deallocate(NULL, why2_chat_server_config("server_username"), connection, WHY2_CHAT_CODE_ENTER_PASSWORD); send_socket_code_deallocate(NULL, why2_chat_server_config("server_username"), connection, WHY2_CHAT_CODE_ENTER_PASSWORD);
//KEEP READING UNTIL CODE ARRIVES
char *code = NULL;
why2_bool exiting_read = 0;
do
{
//DEALLOCATE
why2_deallocate(code);
if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ
{ {
force_exiting = 1; //FAILURE force_exiting = 1; //FAILURE
goto deallocation; goto deallocation;
} }
//COMPARE CODE
code = get_string_from_json_string(raw, "code");
exiting_read = code != NULL && strcmp(code, WHY2_CHAT_CODE_PASSWORD) == 0;
} while (!exiting_read);
why2_deallocate(code);
password = get_string_from_json_string(raw, "message"); //DECODE password = get_string_from_json_string(raw, "message"); //DECODE
why2_toml_write(user_config_path, username, password); //SAVE PASSWORD why2_toml_write(user_config_path, username, password); //SAVE PASSWORD
@ -634,12 +649,26 @@ void *why2_communicate_thread(void *arg)
for (unsigned char i = 0; i < max_tries; i++) for (unsigned char i = 0; i < max_tries; i++)
{ {
//KEEP READING UNTIL CODE ARRIVES
char *code = NULL;
why2_bool exiting_read = 0;
do
{
//DEALLOCATE
why2_deallocate(code);
if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ
{ {
force_exiting = 1; //FAILURE force_exiting = 1; //FAILURE
goto deallocation; goto deallocation;
} }
//COMPARE CODE
code = get_string_from_json_string(raw, "code");
exiting_read = code != NULL && strcmp(code, WHY2_CHAT_CODE_PASSWORD) == 0;
} while (!exiting_read);
why2_deallocate(code);
password = get_string_from_json_string(raw, "message"); //DECODE password = get_string_from_json_string(raw, "message"); //DECODE
if (why2_toml_equals(user_config_path, decoded_buffer, password)) break; if (why2_toml_equals(user_config_path, decoded_buffer, password)) break;