mkhorasani / Streamlit-Authenticator

A secure authentication module to validate user credentials in a Streamlit application.
Apache License 2.0
1.38k stars 229 forks source link

I have an "invalid salt" print, without error (no reaction...) #103

Closed BastienGauthier closed 6 months ago

BastienGauthier commented 6 months ago

Each time I try to login with streamlit-authentificator into a streamlit application deployed on a kubernetes pod, I have a "Invalid Salt" print in the terminal, without any error. The login windows does not react. I suspect an issue with the bcrypt librairy, but I can't see where : I tried downgrading to 4.0 and 3.2, no chance.

It works fine in local mode, on windows.

An code exemple :

#%%
# Import
import streamlit as st
import streamlit_authenticator as stauth

#My config variables
username='my_user'
password='my_hashed_password'
credentials = {
        "usernames":{
            username:{
                "name":'Equipe',
                "password":password
                }
        }}
# print(credentials)
expiry_days = 30 
key = 'random_signature_key'
name = 'random_cookie_name' 

authenticator = stauth.Authenticate(credentials, name, key, expiry_days)
#%%

# hide collapsed control button
hide_bar = """
           <style>
           [data-testid='collapsedControl"] {visibility:hidden;}
           </style>
           """ 
# %%
name, st.session_state['authentication_status'], username = authenticator.login('Login', 'main')
if st.session_state['authentication_status']:
    authenticator.logout('Logout', 'main')
    st.sidebar.title(f'Welcome *{name}*!')
    # Application
    st.write("## Choisissez l'application qui vous intéresse")
    st.write("Cette application vise à exploiter les données des postes sources de manière plus fine que la représentation cartographique.")
    st.info("Choisissez l'application qui vous intéresse dans la barre latérale !", icon="◀️")
elif st.session_state['authentication_status'] == False:
    st.error('Username/password is incorrect')
    st.session_state.sidebar_state = 'collapsed'
    st.markdown(hide_bar, unsafe_allow_html=True)
elif st.session_state['authentication_status'] == None:
    st.warning('Please enter your username and password')
mkhorasani commented 6 months ago

Hi @BastienGauthier, your password in the config file is not hashed, please use stauth.Hasher(['my_hashed_password']).generate() to hash your password. It should look something like this - $2b$12$E9/bCaN/r8sN/FV2l8NpgOgspUBAp7UAVU6BgsXJzp/pW8gQWCprC

BastienGauthier commented 6 months ago

Actually, I wrote "my_hashed_password" not to disclose any credential, but it is hashed in the real configuration file. I use the same on windows and it works : it is really a windows vs kubernetes pods issue. Using the stauth hashing instead of the previous use solved the issue though.