From 30b2ef6afd59e24ae74e9aae5f20eca79a719e31 Mon Sep 17 00:00:00 2001 From: Szymon P Date: Wed, 11 Feb 2026 21:56:47 +0100 Subject: [PATCH] Added secure password storing with keyring --- setup.py | 3 ++- zut_app/zutui.py | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 75bd356..7e097ce 100644 --- a/setup.py +++ b/setup.py @@ -8,10 +8,11 @@ setup( "requests", "beautifulsoup4", "textual", + "keyring" ], entry_points={ 'console_scripts': [ 'zutui=zut_app.zutui:main', ], }, -) \ No newline at end of file +) diff --git a/zut_app/zutui.py b/zut_app/zutui.py index 6c25d68..58975fb 100644 --- a/zut_app/zutui.py +++ b/zut_app/zutui.py @@ -1,5 +1,7 @@ import json import os +import keyring +from keyring.errors import KeyringError from datetime import datetime from textual.app import App, ComposeResult from textual.containers import Container @@ -54,9 +56,20 @@ class LoginScreen(Screen): if success: try: with open(CONFIG_FILE, "w") as f: - json.dump({"username": user, "password": password}, f) + json.dump({"username": user}, f) + keyring.set_password("zutui", user, password) + except KeyringError as e: + error = e + self.app.call_from_thread( + lambda: + self.app.notify( + f"Błąd: {str(error)}", + title="Błąd zapisu hasła do systemowego menedżera haseł", + severity="warning", + timeout=5 + ) + ) except: pass - def do_switch(): self.app.switch_screen(DashboardScreen()) self.app.call_from_thread(do_switch) @@ -406,7 +419,8 @@ class ZutApp(App): try: with open(CONFIG_FILE, "r") as f: creds = json.load(f) - self.zut_client = ZUT(creds["username"], creds["password"]) + password = keyring.get_password("zutui", creds["username"]) + self.zut_client = ZUT(creds["username"], password) self.push_screen(DashboardScreen()) except: self.push_screen(LoginScreen())