Streamlit authentication problems - can't log in

Hello,

I need some help!
I am trying to create a user authentication for my multipage streamlit app and i create a YAML file as follows:

credentials:
usernames:
user1:
password: password1
user2:
password: password2

cookie:
expiry_days: 100
key: some_signature_key
name: some_cookie_name

for now, I want to ignore the hashing of passwords as this is just for development.

This is the code on my homepage. Why is it that I cant seem to login in when i input user1 and password 1 respectively?

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’)

It looks like streamlit-authenticator only works with hashed passwords, so when you put in the raw passwords it won’t work.

1 Like

Yes got it thank you!

Hello blackary, thanks so much for your help!
I managed to solve the authentication problem but have a new issue.
I created a multi page streamlit app and created 2 authentication fields - one login widget for existing users and one register new user widget.
When I run the app locally, the user details (name/email/hashed passwords) are automatically written into my config.yaml file.

However, I have now deployed my app on the streamlit cloud, where the code is hosted in github. I connected streamlit to googlesheets and I am now trying to get it to write the yaml data into an empty google sheet so that I can collect the information of new users.

However, it keeps throwing up this error: ValueError: I/O operation on closed file. Please help!

this is the line that keeps throwing up the error:

yaml_data= yaml.dump(config, file, default_flow_style=False)

How do i save this yaml dump data into a google sheet? pls help! thank u!

I have already connected it to GCP here:
gc = gspread.service_account(filename=‘gcp-creds.json’)
worksheet = gc.open(‘config’).get_worksheet(0)

I would recommend skipping the yaml step, and just writing the data directly to the sheet. You could even use the experimental GitHub - streamlit/gsheets-connection if that seems helpful. I don’t believe a worksheet will function well as an open file, which is what yaml.dump expects.

Thanks blackary! I fixed it! Not sure if this is the best method but this is what I did: I hosted the yaml config file in a google cloud storage bucket. So this means that when the app is deployed on streamlit cloud, it reads the code from github, but gets the config yaml file from GCS. And when a new user registers, it will write the new user particulars into the yaml file in GCS. If I want to view the particulars of new registered users, I’ll just need to download that yaml file from GCS.

Let me know your thoughts and if there’s a better way to do this! I am not sure if a gsheets connection would work cos I believe the config file needs to be in yml format?

That seems like a great solution. Yeah, it does look like streamlit-authenticator does require a yaml file, so that seems like a good way to go.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.