|
|
|
import streamlit as st |
|
import pandas as pd |
|
import os |
|
|
|
|
|
def load_users(): |
|
if not os.path.exists("users.csv"): |
|
df = pd.DataFrame(columns=["username", "password", "role"]) |
|
df.to_csv("users.csv", index=False) |
|
return pd.read_csv("users.csv") |
|
|
|
|
|
def save_users(df): |
|
df.to_csv("users.csv", index=False) |
|
|
|
|
|
def register_user(username, password, role): |
|
users = load_users() |
|
if username in users["username"].values: |
|
return False |
|
new_user = pd.DataFrame({"username": [username], "password": [password], "role": [role]}) |
|
users = pd.concat([users, new_user], ignore_index=True) |
|
save_users(users) |
|
return True |
|
|
|
|
|
def authenticate_user(username, password): |
|
users = load_users() |
|
user = users[(users["username"] == username) & (users["password"] == password)] |
|
if not user.empty: |
|
return user.iloc[0]["role"] |
|
return None |