mirror of
https://github.com/szymon-jozef/zutui.git
synced 2026-09-07 20:20:42 +02:00
Added secure password storing with keyring
This commit is contained in:
1
setup.py
1
setup.py
@@ -8,6 +8,7 @@ setup(
|
|||||||
"requests",
|
"requests",
|
||||||
"beautifulsoup4",
|
"beautifulsoup4",
|
||||||
"textual",
|
"textual",
|
||||||
|
"keyring"
|
||||||
],
|
],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import keyring
|
||||||
|
from keyring.errors import KeyringError
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.containers import Container
|
from textual.containers import Container
|
||||||
@@ -54,9 +56,20 @@ class LoginScreen(Screen):
|
|||||||
if success:
|
if success:
|
||||||
try:
|
try:
|
||||||
with open(CONFIG_FILE, "w") as f:
|
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
|
except: pass
|
||||||
|
|
||||||
def do_switch():
|
def do_switch():
|
||||||
self.app.switch_screen(DashboardScreen())
|
self.app.switch_screen(DashboardScreen())
|
||||||
self.app.call_from_thread(do_switch)
|
self.app.call_from_thread(do_switch)
|
||||||
@@ -406,7 +419,8 @@ class ZutApp(App):
|
|||||||
try:
|
try:
|
||||||
with open(CONFIG_FILE, "r") as f:
|
with open(CONFIG_FILE, "r") as f:
|
||||||
creds = json.load(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())
|
self.push_screen(DashboardScreen())
|
||||||
except:
|
except:
|
||||||
self.push_screen(LoginScreen())
|
self.push_screen(LoginScreen())
|
||||||
|
|||||||
Reference in New Issue
Block a user