File size: 1,248 Bytes
915b731
 
 
3f94976
915b731
3f94976
915b731
3f94976
 
 
 
915b731
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f94976
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# /modules/auth.py
import streamlit as st
import pandas as pd
import os

# Funci贸n para cargar usuarios
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")

# Funci贸n para guardar usuarios
def save_users(df):
    df.to_csv("users.csv", index=False)

# Funci贸n para registrar un nuevo usuario
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

# Funci贸n para autenticar un usuario
def authenticate_user(username, password):
    users = load_users()
    user = users[(users["username"] == username) & (users["password"] == password)]
    if not user.empty:
        return True
    return False

# Funci贸n para obtener el rol del usuario
def get_user_role(username):
    users = load_users()
    user = users[users["username"] == username]
    if not user.empty:
        return user.iloc[0]["role"]
    return None