Streamlit-Authenticator, Part 1: Adding an authentication component to your app

I created a sample app that uses streamlit’s multi-page feature and authenticator. The source code is in github.

To login you can use username paul with password Peace. Or username alan with password Judge.

I appreciate the example you provided. I installed your application by preparing a secret.toml file in the .streamlit folder. I added the necessary username, password, and other information. I successfully implemented multi-user logins without any issues. In my own code, I had made some modifications to use DetaSpace. I suspect these modifications might be eliminating the JWT token. If I follow the logic of the get_auth() function, I should be able to resolve the issue. Alternatively, I may continue with secrets.toml. Maybe, I could integrate Streamlit with a CMS. I have completed the demo version of my own application; I just need to improve it in terms of database management. Thank you very much for the example application you provided; it has enhanced my perspective.

I did try the deta space drive. Created the config.yaml file in deta drive. To update, I download it as a file stream update the users in the app from memory and send the config file back to deta. No physical writing is involved. It worked.

Hello guys, i had this problem since the latest release last night (v0.2.4):

File “C:\Users\Gary\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit_authenticator\authenticate.py”, line 128, in _check_cookie
st.session_state[‘name’] = self.credentials[‘usernames’][st.session_state[‘username’]][‘name’]

KeyError: False

I’ve checked in the source code of the library, and I think that could be an error with the decoding of the token while getting the ‘username’ but I don’t know why… Does anyone have the same error ? Please help me…

Thank you guys

Thank you for the explanations, I will do as you mentioned.

Mine, upgrading to 0.2.4 would result to:

 File "F:\Github\VivaChronicle\pages\4_📝_Todo.py", line 17, in <module>
    authenticator = get_auth()
                    ^^^^^^^^^^
  File "F:\Github\VivaChronicle\modules\auth.py", line 9, in get_auth
    return stauth.Authenticate(
           ^^^^^^^^^^^^^^^^^^^^
  File "F:\Github\VivaChronicle\venv\Lib\site-packages\streamlit_authenticator\authenticate.py", line 50, in __init__
    self.credentials['usernames'][username]['logged_in'] = False
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "F:\Github\VivaChronicle\venv\Lib\site-packages\streamlit\runtime\secrets.py", line 105, in __setitem__
    raise TypeError("Secrets does not support item assignment.")
TypeError: Secrets does not support item assignment.

This is because my users info are in secrets.toml.

If I use config.yaml, it will work just fine.

I had written the code on Deta integration for config.yaml. That app can also do user registration. Forgot password is also implemented, but the method to send the random password to the email of the registered user who forgot the password is not yet implemented.

I raise an issue on this.

Is the Authenticator actually safe for prodcution use cases? so would it be safe enough or would it be better to include a separate authenticator in the backend.

Hello everyone, I’m currently working on a project and I’m using the Streamlit-Authenticator. However, I’ve encountered an issue where I have a large dataset of credentials in the config.yaml file, causing my Streamlit app to be extremely slow and barely usable.
Any solution ?

How many user are there in that config.yaml file?

Hello,
Can anyone tell me how does the password gets hashed or how does it get checked? Im having trouble checking the values against the ones stored in my db.
For the DB i used stauth.Hasher(password).generate() which i would guess would be just fine, but cant seem to find why, i cant perform a login.
Thanks in advance!

There are 280 users, i tested another config.yaml file with only 4 users, and it was much faster.

What version of streamlit and streamlit-authenticator did you use?

Have a look on the readme of streamlit authenticator at github.

Check this code too.

Streamlit, version 1.32.2

I experienced it being slow in the beginning. Then it worked fine later on. Maybe the cache has kicked-in.

Dean_Foulds is right. The tutorial is missing stauth before the .Authenticate – the GitHub repo has the correct code: GitHub - mkhorasani/Streamlit-Authenticator: A secure authentication module to validate user credentials in a Streamlit application.

Do you mean the ‘Username’ and ‘Password’ labels? These ones can’t be customize even with css/html? Thanks in advance.