diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a4e5387..53445937 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [0.7.1] 2019- ### Improvements +- 3 password attempts for root authentication - AUR: - showing a "user-friendly" popup when there are integrity issues with the source-files of a building package ### Fixes diff --git a/bauh/view/qt/root.py b/bauh/view/qt/root.py index 890c487f..d4f16cb0 100644 --- a/bauh/view/qt/root.py +++ b/bauh/view/qt/root.py @@ -13,28 +13,41 @@ def is_root(): return os.getuid() == 0 -def ask_root_password(locale_keys: dict): - +def ask_root_password(i18n: dict): diag = QInputDialog() diag.setStyleSheet("""QLineEdit { border-radius: 5px; font-size: 16px }""") diag.setInputMode(QInputDialog.TextInput) diag.setTextEchoMode(QLineEdit.Password) diag.setWindowIcon(QIcon(resource.get_path('img/lock.png'))) - diag.setWindowTitle(locale_keys['popup.root.title']) + diag.setWindowTitle(i18n['popup.root.title']) diag.setLabelText('') - diag.setCancelButtonText(locale_keys['popup.button.cancel']) + diag.setCancelButtonText(i18n['popup.button.cancel']) diag.resize(400, 200) - ok = diag.exec_() + for attempt in range(3): - if ok: - if not validate_password(diag.textValue()): - show_message(title=locale_keys['popup.root.bad_password.title'], - body=locale_keys['popup.root.bad_password.body'], - type_=MessageType.ERROR) - ok = False + ok = diag.exec_() - return diag.textValue(), ok + if ok: + if not validate_password(diag.textValue()): + + body = i18n['popup.root.bad_password.body'] + + if attempt == 2: + body += '. ' + i18n['popup.root.bad_password.last_try'] + + show_message(title=i18n['popup.root.bad_password.title'], + body=body, + type_=MessageType.ERROR) + ok = False + diag.setTextValue('') + + if ok: + return diag.textValue(), ok + else: + break + + return '', False def validate_password(password: str) -> bool: diff --git a/bauh/view/resources/locale/en b/bauh/view/resources/locale/en index 029a4b4c..04523f1a 100644 --- a/bauh/view/resources/locale/en +++ b/bauh/view/resources/locale/en @@ -38,6 +38,7 @@ manage_window.checkbox.show_details=Show details popup.root.title=Requires your password to continue popup.root.bad_password.title=Error popup.root.bad_password.body=Wrong password +popup.root.bad_password.last_try=Attempts finished. Action cancelled. popup.history.title=History popup.history.selected.tooltip=Current version popup.button.yes=Yes diff --git a/bauh/view/resources/locale/es b/bauh/view/resources/locale/es index dfb29385..b9e055b8 100644 --- a/bauh/view/resources/locale/es +++ b/bauh/view/resources/locale/es @@ -39,6 +39,7 @@ manage_window.checkbox.show_details=Mostrar detalles popup.root.title=Requiere tu contraseña para continuar popup.root.bad_password.title=Error popup.root.bad_password.body=Contraseña incorrecta +popup.root.bad_password.last_try=Intentos finalizados. Acción cancelada. popup.history.title=Historia popup.history.selected.tooltip=Versión actual popup.button.yes=Sí diff --git a/bauh/view/resources/locale/pt b/bauh/view/resources/locale/pt index 728ad2f2..53a7a50d 100644 --- a/bauh/view/resources/locale/pt +++ b/bauh/view/resources/locale/pt @@ -39,6 +39,7 @@ manage_window.checkbox.show_details=Mostrar detalhes popup.root.title=Requer sua senha para prosseguir popup.root.bad_password.title=Erro popup.root.bad_password.body=Senha incorreta +popup.root.bad_password.last_try=Tentativas finalizadas. Ação cancelada. popup.history.title=Histórico popup.history.selected.tooltip=Versão atual popup.button.yes=Sim