File size: 1,587 Bytes
266eda8 | 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 42 43 44 | """
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()
|