mkhorasani / Streamlit-Authenticator

A secure authentication module to manage user access in a Streamlit application.
Other
1.66k stars 259 forks source link

Login issue Username/password is incorrect #206

Closed AvisP closed 1 month ago

AvisP commented 1 month ago

I am trying out a demo example and no matter if I set the autohash to True or False, I cannot get authentication with an username or password in config. I am lost as to what is the issue. Any suggestion would be great.

ST_Version : 1.38.0

import yaml
import streamlit as st
from yaml.loader import SafeLoader
import streamlit_authenticator as stauth
from streamlit_authenticator.utilities import (CredentialsError,
                                               ForgotError,
                                               Hasher,
                                               LoginError,
                                               RegisterError,
                                               ResetError,
                                               UpdateError)

# Loading config file
with open('./data/config.yaml', 'r', encoding='utf-8') as file:
    config = yaml.load(file, Loader=SafeLoader)

print(config)
# Hashing all plain text passwords once
# Hasher.hash_passwords(config['credentials'])

# Creating the authenticator object
authenticator = stauth.Authenticate(
    config['credentials'],
    config['cookie']['name'],
    config['cookie']['key'],
    config['cookie']['expiry_days'],
    config['pre-authorized'],
    auto_hash=True,
)

# Creating a login widget
try:
    authenticator.login()
except LoginError as e:
    st.error(e)

if st.session_state["authentication_status"]:
    authenticator.logout()
    st.write(f'Welcome *{st.session_state["name"]}*')
    st.title('Some content')
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')

# Saving config file
with open('../config.yaml', 'w', encoding='utf-8') as file:
    yaml.dump(config, file, default_flow_style=False)

And here is the config file

credentials:
  usernames:
    jsmith:
      email: jsmith@gmail.com
      failed_login_attempts: 0 # Will be managed automatically
      logged_in: False # Will be managed automatically
      name: John Smith
      password: abc # Will be hashed automatically
    rbriggs:
      email: rbriggs@gmail.com
      failed_login_attempts: 0 # Will be managed automatically
      logged_in: False # Will be managed automatically
      name: Rebecca Briggs
      password: def # Will be hashed automatically
cookie:
  expiry_days: 30
  key: "e324670610d643aa0f4f04717f4ed8713297343c45bec4024f9c01e1f8fa9a97"
  name: test_cookie
pre-authorized:
  emails:
  - melsby@gmail.com
AvisP commented 1 month ago

Any update on this? or workaround possible?

mkhorasani commented 1 month ago

Hi @AvisP, apologies for the delay. I am working on v0.3.4, which I hope can resolve this issue. I will try to release by the end of September.

EdwardSJ151 commented 1 month ago

Is there a temporary fix, like using a certain version of streamlit?

mkhorasani commented 1 month ago

I just released the latest version, please try it.

AvisP commented 1 month ago

Thanks it is working now! Can be closed.