SecureAuthentication / storage.py
Mangesh223's picture
Create storage.py
805f8a4 verified
raw
history blame contribute delete
520 Bytes
import json
import os
from pathlib import Path
DATA_FILE = "users.json"
def load_users():
if not Path(DATA_FILE).exists():
return {}
with open(DATA_FILE, "r") as f:
return json.load(f)
def save_users(users):
with open(DATA_FILE, "w") as f:
json.dump(users, f)
def add_user(username, hashed_password):
users = load_users()
users[username] = {"password": hashed_password}
save_users(users)
def get_user(username):
users = load_users()
return users.get(username)