Initial commit - Navi.FM v3

This commit is contained in:
Collin Kasbergen
2026-07-22 13:23:22 +02:00
commit badafc91e3
55 changed files with 6384 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
import os
from cryptography.fernet import Fernet, InvalidToken
def get_fernet():
key = os.environ.get("ENCRYPTION_KEY")
if not key:
# Fallback to an ephemeral key if missing to prevent crashing,
# though data encrypted with this will be lost on restart
key = Fernet.generate_key()
os.environ["ENCRYPTION_KEY"] = key.decode('utf-8')
return Fernet(key)
def encrypt_password(password: str) -> str:
if not password:
return password
f = get_fernet()
return f.encrypt(password.encode('utf-8')).decode('utf-8')
def decrypt_password(token: str) -> str:
if not token:
return token
f = get_fernet()
try:
return f.decrypt(token.encode('utf-8')).decode('utf-8')
except InvalidToken:
# If decryption fails, assume it's a legacy plaintext password
return token