gelpredict / app /auth.py
awolter's picture
Upload folder using huggingface_hub
266eda8 verified
Raw History Blame Contribute Delete
1.59 kB
"""
Simple authentication for GelPredict
Adds password protection to the deployed app
"""
import streamlit as st
import hashlib
# Simple password hash (in production, use proper authentication)
PASSWORD_HASH = "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8" # "password"
def check_password():
"""Returns `True` if the user had the correct password."""
def password_entered():
"""Checks whether a password entered by the user is correct."""
if hashlib.sha256(st.session_state["password"].encode()).hexdigest() == PASSWORD_HASH:
st.session_state["password_correct"] = True
del st.session_state["password"] # Don't store password
else:
st.session_state["password_correct"] = False
# Return True if the password is validated.
if st.session_state.get("password_correct", False):
return True
# Show input for password.
st.markdown("## 🔐 GelPredict Access")
st.markdown("Please enter the access key to continue:")
st.text_input("Access Key", type="password", on_change=password_entered, key="password")
if "password_correct" in st.session_state:
if not st.session_state["password_correct"]:
st.error("😕 Access denied. Please check your access key.")
return False
def show_access_denied():
"""Show a message when access is denied."""
st.markdown("## 🔐 Access Required")
st.markdown("This application requires an access key.")
st.markdown("Please contact the administrator for access.")
st.stop()