File size: 1,019 Bytes
dcb5e21
 
422eddd
dcb5e21
 
 
 
422eddd
dcb5e21
422eddd
dcb5e21
 
 
 
 
 
422eddd
dcb5e21
 
 
 
 
422eddd
dcb5e21
 
 
 
 
 
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
import streamlit as st

def check_password(key):
    """Returns `True` if the user had the correct password."""

    def password_entered():
        """Checks whether a password entered by the user is correct."""
        if st.session_state[key] == st.secrets[key]:
            st.session_state["password_correct"] = True
            del st.session_state[key]  # don't store password
        else:
            st.session_state["password_correct"] = False

    if "password_correct" not in st.session_state:
        # First run, show input for password.
        st.text_input(
            "Password", type="password", on_change=password_entered, key=key
        )
        return False
    elif not st.session_state["password_correct"]:
        # Password not correct, show input + error.
        st.text_input(
            "Password", type="password", on_change=password_entered, key=key
        )
        st.error("πŸ˜• Password incorrect")
        return False
    else:
        # Password correct.
        return True