Spaces:
Sleeping
Sleeping
| import bcrypt | |
| from db import users_collection | |
| def signup(username, password, role): | |
| hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt()) | |
| user = { | |
| "username": username, | |
| "password": hashed, | |
| "role": role | |
| } | |
| users_collection.insert_one(user) | |
| return "Signup Successful" | |
| def login(username, password): | |
| user = users_collection.find_one({"username": username}) | |
| if user and bcrypt.checkpw(password.encode(), user["password"]): | |
| return user["role"] | |
| return None |