MrJShen commited on
Commit
dcb5e21
·
1 Parent(s): 7878c8d

Upload utils.py

Browse files

Add password checking utils

Files changed (1) hide show
  1. utils.py +29 -0
utils.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def check_password():
4
+ """Returns `True` if the user had the correct password."""
5
+
6
+ def password_entered():
7
+ """Checks whether a password entered by the user is correct."""
8
+ if st.session_state["password"] == st.secrets["password"]:
9
+ st.session_state["password_correct"] = True
10
+ del st.session_state["password"] # don't store password
11
+ else:
12
+ st.session_state["password_correct"] = False
13
+
14
+ if "password_correct" not in st.session_state:
15
+ # First run, show input for password.
16
+ st.text_input(
17
+ "Password", type="password", on_change=password_entered, key="password"
18
+ )
19
+ return False
20
+ elif not st.session_state["password_correct"]:
21
+ # Password not correct, show input + error.
22
+ st.text_input(
23
+ "Password", type="password", on_change=password_entered, key="password"
24
+ )
25
+ st.error("😕 Password incorrect")
26
+ return False
27
+ else:
28
+ # Password correct.
29
+ return True