-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.py
47 lines (36 loc) · 1.35 KB
/
auth.py
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
45
46
47
import streamlit as st
import streamlit_authenticator as stauth
# st.set_page_config(
# page_title="Authentication",
# )
# st.sidebar.header("Authentication")
# st.text("Authentication")
# hashed_passwords = stauth.Hasher(['abc', 'def']).generate()
import yaml
from yaml.loader import SafeLoader
with open('./config.yaml') as file:
config = yaml.load(file, Loader=SafeLoader)
authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['preauthorized']
)
name, authentication_status, username = authenticator.login('Login', 'main')
# if authentication_status:
# authenticator.logout('Logout', 'main')
# st.write(f'Welcome *{name}*')
# st.title('Some content')
# elif authentication_status == False:
# st.error('Username/password is incorrect')
# elif authentication_status == None:
# st.warning('Please enter your username and password')
if st.session_state["authentication_status"]:
authenticator.logout('Logout', 'main')
st.write(f'Welcome *{st.session_state["name"]}*')
st.title('Some content')
elif st.session_state["authentication_status"] == False:
st.error('Username/password is incorrect')
elif st.session_state["authentication_status"] == None:
st.warning('Please enter your username and password')