Login form

Hello i’m a new user of streamlit and i am trying to do a login form, but i face some issues.
I tried to use the streamlit-authenticator library, i used the script bellow :

import streamlit as st
import pickle
from pathlib import Path
import streamlit_authenticator as stauth

st.set_page_config(page_title=“app”, layout=“wide”)

names = [“User1 name1”, “User2 name2”]
usernames = [“uname1”, “uname2”]

load hashed passwords

file_path = Path(file).parent / “hashed_pw.pkl”
with file_path.open(“rb”) as file:
hashed_passwords = pickle.load(file)

authenticator = stauth.Authenticate(names, usernames, hashed_passwords,
“App”, “abcdef”, cookie_expiry_days=30)

name, authentication_status, username = authenticator.login(“Login”, “main”)

if authentication_status == False:
st.error(“Username/password is incorrect”)

if authentication_status == None:
st.warning(“Please enter your username and password”)

if authentication_status:
“Body App”

Note : I stored the passwords in hashed_pw.pkl file.

When i run that code, i got this Error : streamlit.runtime.scriptrunner.script_runner.StopException File “path”, loginobj = login(auth_token = “courier_auth_token”.

What can i do to resolve this ?
Also, if there is another library to do this, i take it.

Thank you for you answers !
Happy streamlit ing

Have a look at this streamlit_login_auth_ui authenticator.

Sample code from site.

import streamlit as st
from streamlit_login_auth_ui.widgets import __login__

__login__obj = __login__(auth_token = "courier_auth_token", 
                    company_name = "Shims",
                    width = 200, height = 250, 
                    logout_button_name = 'Logout', hide_menu_bool = False, 
                    hide_footer_bool = False, 
                    lottie_url = 'https://assets2.lottiefiles.com/packages/lf20_jcikwtux.json')

LOGGED_IN = __login__obj.build_login_ui()


    st.markown("Your Streamlit Application Begins here!")

If you are comfortable with that, you can try the PR I made with some improvements.

You can also try the Streamlit Authentication without SSO.

Hello fredy, thank you for the reply.
About the example code you give me, in order to try it, i installed :

  • pip install streamlit-login-auth-ui
  • pip install argon2-cffi

And after runing the same code, i got this error :
Traceback (most recent call last) :
File “path”, line 6, in __login__obj = login(auth_token = “courier_auth_token”,
File “path”, line 54, in __init__st.stop()
File “path”, line 41, in stop raise StopException()

can you help me fixing this ?

May I know the following.

Streamlit version?
Python version?

Of course, here are the information:
i an using :
Windows 10
Streamlit, version 1.16.0
Python 3.10.5

Let’s try the following setup.

  1. Open powershell and create a temp_streamlit folder from your c drive or any drive.


  1. cd to temp_streamlit folder and check you python version.


  1. Create a virtual environment folder called venv with:
    python -m venv venv


  1. Clone the repo of aut ui with:
    git clone https://github.com/GauriSP10/streamlit_login_auth_ui


  1. Activate the virtual environment. We will install streamlit and other needed packages.


  1. Update pip with:
    python -m pip install pip -U

  2. Install streamlit with:
    pip install streamlit

  3. Install the auth ui package with:
    pip install streamlit-login-auth-ui

  4. Install argon with:
    pip install argon2-cffi

  5. cd to the aut ui folder and run the app.
    There is app.py under streamlit_login_auth_ui folder.


You should see something like this.

If you no longer need it, just delete temp_streamlit folder.

Oh Thank you so much, i followed your steps and it works. i just have a last question : when i run the script using the play button i got this error (in my first message), but when i write in the terminal : “streamlit run app.py” it works correctly. it’s confusing me

I don’t understand that. What is play button?

i am using visual studio code, as ide, i am talking About the “Run python file” button

Ahh ok, I also use vs code. But I don’t use that button to run streamlit.

Ok, Thank you very much for your help !