1
0
Fork 0
forked from Fuji/Fuji

Refactor authentication functions and move them to a new utils module

This commit is contained in:
Maarceeli 2025-02-22 13:19:40 +01:00
parent 20db69ef4d
commit b17be83791
2 changed files with 18 additions and 18 deletions

15
src/utils.py Normal file
View file

@ -0,0 +1,15 @@
import keyring
def saveauth(service, username, data, chunk_size=1000):
chunks = [data[i:i+chunk_size] for i in range(0, len(data), chunk_size)]
keyring.set_password(service, f"{username}_count", str(len(chunks)))
for i, chunk in enumerate(chunks):
keyring.set_password(service, f"{username}_{i}", chunk)
def loadauth(service, username):
try:
count = int(keyring.get_password(service, f"{username}_count"))
return "".join(keyring.get_password(service, f"{username}_{i}") or "" for i in range(count))
except (TypeError, ValueError):
return None