Streamlit-Authenticator
Streamlit-Authenticator copied to clipboard
Can't Login in any way
Hello, I'm just following the official docs but it doesn't work, I can't login either with hashed or not hashed password...
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'],
auto_hash=False # I've tried with True and stauth.Hasher.hash_passwords(config['credentials'])
)
# [...]
def main():
# Authentication
authenticator.login(location='main')
if st.session_state["authentication_status"]:
authenticator.logout('Logout', 'sidebar')
st.sidebar.write(f'Welcome *{st.session_state["name"]}*')
elif st.session_state["authentication_status"] == False:
st.error('Username/password is incorrect') #<-- always
Hi if you follow the exact same codes described in step 4, 5, 7 and 13 link, it should be no problem.
Try checking your config.yaml file. I had the same issue if I used the email instead of 'usernames' YAML key.
After much trial and error, this worked for me. The issue was in the config file.
cookie:
expiry_days: 30
key: some_signature_key # Must be a string
name: some_cookie_name
credentials:
usernames:
[email protected]:
email: [email protected]
name: User name
password: $2b$12$sK6am.2wEC/wsRcKxtglQOJvgGKA7OT6lVaPZ96yfDCHrzo7JwN3W
pre-authorized:
- [email protected]
This is how to use it.
import streamlit as st
import streamlit_authenticator as stauth
from streamlit_authenticator.utilities import LoginError
import yaml
from yaml.loader import SafeLoader
with open("./auth_config.yaml") as file:
auth_config = yaml.load(file, Loader=SafeLoader)
authenticator = stauth.Authenticate(
auth_config["credentials"],
auth_config["cookie"]["name"],
auth_config["cookie"]["key"],
auth_config["cookie"]["expiry_days"],
)
try:
authenticator.login("main")
except LoginError as e:
st.error(e)
if st.session_state["authentication_status"]:
st.write(f"Welcome *{st.session_state['name']}*")
authenticator.logout("Logout")
elif st.session_state["authentication_status"] is False:
st.error("Username/password is incorrect")
elif st.session_state["authentication_status"] is None:
st.warning("Please enter your username and password")