diff --git a/nitrokeyapp/secrets_tab/__init__.py b/nitrokeyapp/secrets_tab/__init__.py index d1b9c5e7..e5a42509 100644 --- a/nitrokeyapp/secrets_tab/__init__.py +++ b/nitrokeyapp/secrets_tab/__init__.py @@ -178,8 +178,11 @@ def __init__(self, parent: Optional[QWidget] = None) -> None: self.ui.btn_edit.pressed.connect(self.prepare_edit_credential) self.ui.name.textChanged.connect(self.check_credential) + self.ui.username.textChanged.connect(self.check_credential) + self.ui.password.textChanged.connect(self.check_credential) self.ui.otp.textChanged.connect(self.check_credential) self.ui.select_algorithm.currentIndexChanged.connect(self.check_credential) + self.ui.comment.textChanged.connect(self.check_credential) self.ui.btn_refresh.pressed.connect(self.refresh_credential_list) self.ui.is_protected.stateChanged.connect(self.refresh_credential_list) @@ -363,13 +366,14 @@ def show_credential(self, credential: Credential) -> None: self.ui.name.hide() self.ui.name_label.show() + self.ui.name.setText(credential.name) self.ui.name_label.setText(credential.name) if credential.login: self.ui.username.setText(credential.login.decode(errors="replace")) self.action_username_copy.setEnabled(True) else: - self.ui.username.setText("") + self.ui.username.clear() self.action_username_copy.setEnabled(False) if credential.password: @@ -377,7 +381,7 @@ def show_credential(self, credential: Credential) -> None: self.action_password_copy.setEnabled(True) self.action_password_show.setEnabled(True) else: - self.ui.password.setText("") + self.ui.password.clear() self.action_password_copy.setEnabled(False) self.action_password_show.setEnabled(False) @@ -385,7 +389,7 @@ def show_credential(self, credential: Credential) -> None: self.ui.comment.setText(credential.comment.decode(errors="replace")) self.action_comment_copy.setEnabled(True) else: - self.ui.comment.setText("") + self.ui.comment.clear() self.action_comment_copy.setEnabled(False) self.ui.name.setReadOnly(True) @@ -458,17 +462,17 @@ def edit_credential(self, credential: Credential) -> None: if credential.login: self.ui.username.setText(credential.login.decode(errors="replace")) else: - self.ui.username.setText("") + self.ui.username.clear() if credential.password: self.ui.password.setText(credential.password.decode(errors="replace")) else: - self.ui.password.setText("") + self.ui.password.clear() if credential.comment: self.ui.comment.setText(credential.comment.decode(errors="replace")) else: - self.ui.comment.setText("") + self.ui.comment.clear() self.ui.name.setReadOnly(False) self.ui.username.setReadOnly(False) self.ui.password.setReadOnly(False) @@ -484,6 +488,7 @@ def edit_credential(self, credential: Credential) -> None: self.ui.algorithm_tab.show() self.ui.algorithm_tab.setCurrentIndex(0) + self.ui.select_algorithm.setMaxCount(3) self.ui.algorithm_show.hide() self.ui.algorithm_edit.show() self.ui.select_algorithm.show() @@ -513,7 +518,7 @@ def edit_credential(self, credential: Credential) -> None: # no otp there, just offer it as in add else: - self.ui.otp.setText("") + self.ui.otp.clear() self.ui.otp.setReadOnly(False) self.ui.otp.setPlaceholderText("") self.ui.select_algorithm.setCurrentText(str(credential.otp)) @@ -532,10 +537,9 @@ def act_enable_otp_edit(self) -> None: self.active_credential.new_secret = True self.ui.otp.setReadOnly(False) - self.ui.select_algorithm.setMaxCount(3) self.ui.select_algorithm.setEnabled(True) self.ui.otp.setPlaceholderText("") - self.ui.otp.setText("") + self.ui.otp.clear() self.check_credential() @@ -558,12 +562,13 @@ def add_new_credential(self) -> None: self.ui.name.show() self.ui.name_label.hide() - self.ui.name.setText("") + self.ui.name.clear() - self.ui.otp.setText("") - self.ui.username.setText("") - self.ui.password.setText("") - self.ui.comment.setText("") + self.ui.otp.clear() + self.ui.otp.setPlaceholderText("") + self.ui.username.clear() + self.ui.password.clear() + self.ui.comment.clear() self.ui.name.setReadOnly(False) self.ui.otp.setReadOnly(False) @@ -602,29 +607,83 @@ def add_new_credential(self) -> None: @Slot() def check_credential(self) -> None: + self.info_box.hide_status() + + tool_Tip = "Credeantial cannot be saved:" can_save = True + check_secret = self.ui.otp.text() - otp_secret = self.ui.otp.text() + name_len = len(str.encode(self.ui.name.text())) + username_len = len(str.encode(self.ui.username.text())) + password_len = len(str.encode(self.ui.password.text())) + comment_len = len(str.encode(self.ui.comment.text())) algo = self.ui.select_algorithm.currentText() + + if len(self.ui.name.text()) < 3: + can_save = False + if len(self.ui.name.text()) == 0: + self.info_box.set_status("Enter a Credential Name") + tool_Tip = tool_Tip + "\n- Enter a Credential Name" + if len(self.ui.name.text()) >= 1 and len(self.ui.name.text()) < 3: + self.info_box.set_status("Credential Name is too short") + tool_Tip = tool_Tip + "\n- Credential Name is too short" + if name_len >= 128: + can_save = False + self.info_box.set_status("Credential Name is too long") + tool_Tip = tool_Tip + "\n- Credential Name is too long" + + if username_len >= 128: + can_save = False + self.info_box.set_status("Username is too long") + tool_Tip = tool_Tip + "\n- Username is too long" + + if password_len >= 128: + can_save = False + self.info_box.set_status("Password is too long") + tool_Tip = tool_Tip + "\n- Password is too long" + + if comment_len >= 128: + can_save = False + self.info_box.set_status("Comment is too long") + tool_Tip = tool_Tip + "\n- Comment is too long" + if self.ui.select_algorithm.isEnabled(): + if algo == "None": + self.ui.otp.setReadOnly(True) + self.ui.otp.setPlaceholderText("