From b4b419435c75dfd32d4c2c7d8a39b07a57141437 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Mon, 7 Apr 2025 12:39:33 +0600 Subject: [PATCH] Password changes --- source/ubl-settings-update.c | 113 +++++++++++++++++++++-------------- source/ubl-settings-update.h | 3 + source/ubl-strings.h | 3 +- 3 files changed, 73 insertions(+), 46 deletions(-) diff --git a/source/ubl-settings-update.c b/source/ubl-settings-update.c index 34aad3d..2c4dd8c 100644 --- a/source/ubl-settings-update.c +++ b/source/ubl-settings-update.c @@ -740,6 +740,13 @@ void on_password_encryption_changed(GtkComboBox *self, password_window *dialog){ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->NoEncriptionCheck),0); } +void yon_hash_entry_sensitiveness_update(GtkWidget *, password_window *dialog){ + int hash_type_sensitive = gtk_combo_box_get_active(GTK_COMBO_BOX(dialog->EncryptionCombo)); + int encrypt_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->NoEncriptionCheck)); + if (!encrypt_sensitive&&hash_type_sensitive) gtk_widget_set_sensitive(dialog->PasswordHashEntry,1); + else gtk_widget_set_sensitive(dialog->PasswordHashEntry,0); +} + void on_password_open(GtkWidget *, web_publication_add_window *window){ password_window *dialog = yon_password_window_new(); yon_gtk_entry_set_password_visibility_icon(GTK_ENTRY(dialog->PasswordEntry)); @@ -749,8 +756,10 @@ void on_password_open(GtkWidget *, web_publication_add_window *window){ yon_dictionary_add_or_create_if_exists_with_data(dict,"window",dialog); yon_dictionary_add_or_create_if_exists_with_data(dict,"target",window->UserPasswordEntry); g_signal_connect(G_OBJECT(dialog->AcceptButton),"clicked",G_CALLBACK(on_password_accept),dict); - g_signal_connect(G_OBJECT(dialog->NoEncriptionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),dialog->PasswordHashEntry); + g_signal_connect(G_OBJECT(dialog->NoEncriptionCheck),"toggled",G_CALLBACK(yon_hash_entry_sensitiveness_update),dialog); + g_signal_connect(G_OBJECT(dialog->EncryptionCombo),"changed",G_CALLBACK(yon_hash_entry_sensitiveness_update),dialog); g_signal_connect(G_OBJECT(dialog->EncryptionCombo),"changed",G_CALLBACK(on_password_encryption_changed),dialog); + yon_gtk_window_setup(GTK_WINDOW(dialog->Window),GTK_WINDOW(window->Window),PASSWORD_INPUT_LABEL,icon_path,"password_window"); } void on_web_publish_remove(GtkWidget *self,main_window *widgets){ @@ -1371,67 +1380,81 @@ void on_mirror_configure_accept(GtkWidget *, dictionary *dict){ gtk_widget_destroy(window->Window); } -void on_password_accept(GtkWidget *,dictionary *dict){ - password_window *window = yon_dictionary_get_data(dict->first,password_window*); - GtkWidget *target = yon_dictionary_get_data(dict->first->next,GtkWidget*); +char *yon_password_unencrypted_password_get(password_window *window){ + const char *password = gtk_entry_get_text(GTK_ENTRY(window->PasswordEntry)); + const char *password_repeat = gtk_entry_get_text(GTK_ENTRY(window->RepeatPasswordEntry)); + if (strpbrk(password,"!@#%^&*\'")){ + yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),PASSWORD_RESTRICTED_SYMBOL_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); + yon_ubl_status_highlight_incorrect(window->PasswordEntry); + return NULL; + } + if (strcmp(password,password_repeat)){ + yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),PASSWORD_MISMATCH_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); + yon_ubl_status_highlight_incorrect(window->PasswordEntry); + yon_ubl_status_highlight_incorrect(window->RepeatPasswordEntry); + return NULL; + } + if (yon_char_is_empty(password)){ + yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); + yon_ubl_status_highlight_incorrect(window->PasswordEntry); + return NULL; + } + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->NoEncriptionCheck))){ + const char *encryption = gtk_combo_box_get_active_id(GTK_COMBO_BOX(window->EncryptionCombo)); + char *final = yon_char_unite(encryption,"|",password,NULL); + return final; + } else { + return yon_char_new(password); + } +} +char *yon_password_hash_get(password_window *window){ int encription_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->EncryptionCombo)); const char *encription = gtk_combo_box_get_active_id(GTK_COMBO_BOX(window->EncryptionCombo)); - if (encription_active == 0){ + const char *hash = gtk_entry_get_text(GTK_ENTRY(window->PasswordHashEntry)); + if (!yon_char_is_empty(hash)){ + char *final = yon_char_unite(encription,"|",hash); + return final; + } else { const char *password = gtk_entry_get_text(GTK_ENTRY(window->PasswordEntry)); const char *password_repeat = gtk_entry_get_text(GTK_ENTRY(window->RepeatPasswordEntry)); if (strpbrk(password,"!@#%^&*\'")){ yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),PASSWORD_RESTRICTED_SYMBOL_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); yon_ubl_status_highlight_incorrect(window->PasswordEntry); - return; + return NULL; } if (strcmp(password,password_repeat)){ yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),PASSWORD_MISMATCH_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); yon_ubl_status_highlight_incorrect(window->PasswordEntry); yon_ubl_status_highlight_incorrect(window->RepeatPasswordEntry); - return; + return NULL; } - gtk_entry_set_text(GTK_ENTRY(target),password); - } else { - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->NoEncriptionCheck))){ - const char *hash = gtk_entry_get_text(GTK_ENTRY(window->PasswordHashEntry)); - if (yon_char_is_empty(hash)){ - yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - yon_ubl_status_highlight_incorrect(window->PasswordHashEntry); - return; - } - if (strlen((hash))!=128||strlen(hash)!=64){ - yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),INCORRECT_HASH_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - yon_ubl_status_highlight_incorrect(window->PasswordHashEntry); - return; - } - char *final = yon_char_unite(encription,"|",hash,NULL); - gtk_entry_set_text(GTK_ENTRY(target),final); - free(final); - } else { - const char *password = gtk_entry_get_text(GTK_ENTRY(window->PasswordEntry)); - const char *password_repeat = gtk_entry_get_text(GTK_ENTRY(window->RepeatPasswordEntry)); - if (strpbrk(password,"!@#%^&*\'")){ - yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),PASSWORD_RESTRICTED_SYMBOL_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - yon_ubl_status_highlight_incorrect(window->PasswordEntry); - return; - } - if (strcmp(password,password_repeat)){ - yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),PASSWORD_MISMATCH_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - yon_ubl_status_highlight_incorrect(window->PasswordEntry); - yon_ubl_status_highlight_incorrect(window->RepeatPasswordEntry); - return; - } - int size; - config_str hash = yon_config_load(yon_debug_output("%s\n",encription_active==1?sha512_encrypt_command(password):sha256_encrypt_command(password)),&size); - yon_char_remove_last_symbol(hash[0],'\n'); + int size; + config_str hash = yon_config_load(yon_debug_output("%s\n",encription_active==1?sha512_encrypt_command(password):sha256_encrypt_command(password)),&size); + yon_char_remove_last_symbol(hash[0],'\n'); - char *final = yon_char_unite(encription,"|",hash[0],NULL); - gtk_entry_set_text(GTK_ENTRY(target),final); - free(final); - } + char *final = yon_char_unite(encription,"|",hash[0],NULL); + return final; + } + return NULL; +} + +void on_password_accept(GtkWidget *,dictionary *dict){ + password_window *window = yon_dictionary_get_data(dict->first,password_window*); + GtkWidget *target = yon_dictionary_get_data(dict->first->next,GtkWidget*); + + int encription_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->EncryptionCombo)); + char *final = NULL; + if (encription_active == 0||gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->NoEncriptionCheck))){ + final = yon_password_unencrypted_password_get(window); + if (!final) return; + } else { + final = yon_password_hash_get(window); + if (!final) return; } + gtk_entry_set_text(GTK_ENTRY(target),final); gtk_widget_destroy(window->Window); } diff --git a/source/ubl-settings-update.h b/source/ubl-settings-update.h index 1a88728..c6e3ee9 100644 --- a/source/ubl-settings-update.h +++ b/source/ubl-settings-update.h @@ -380,4 +380,7 @@ void on_repo_source_add(GtkWidget *, repo_add_window *window); void on_cell_renderer_toggle_toggled(GtkWidget *self, gchar* path, GtkWidget *table); void on_mirror_configure_accept(GtkWidget *, dictionary *dict); +char *yon_password_unencrypted_password_get(password_window *window); +char *yon_password_hash_get(password_window *window); +void yon_hash_entry_sensitiveness_update(GtkWidget *, password_window *dialog); #endif \ No newline at end of file diff --git a/source/ubl-strings.h b/source/ubl-strings.h index 3b4b9b5..a911688 100644 --- a/source/ubl-strings.h +++ b/source/ubl-strings.h @@ -31,6 +31,8 @@ Configuration - configuration path") #define MIRROR_TOOLTIP_LABEL _("url - web-link for repository. It is allowed to write multiple, separating with comma (,)\n\ http_proxy - proxy-server for repository, replaces 'http_proxy'. Single parameter per repository\n\ mirrorlist - mirrors file, make sure server URL is NOT included in this file! Single parameter per repository") + #define PASSWORD_INPUT_LABEL _("Password input") + /* #define _LABEL _("Signature verification will not be performed") #define _LABEL _("Signatures will be verified if present, but unsigned databases and packages will also be accepted") @@ -153,7 +155,6 @@ mirrorlist - mirrors file, make sure server URL is NOT included in this file! Si #define _LABEL _("Months") #define _LABEL _("Sign level") #define _LABEL _("Description") - #define _LABEL _("Password input") #define _LABEL _("Password:") #define _LABEL _("Repeat password:") #define _LABEL _("Entryption:")