Streamlit password page

Posted under » Python on 13 Jan 2022

Streamlit is new so it doesn't have the depth that Jupyter notebook has when it comes to security.

However, this user password thingie would help. Begin by installing it

$ pip install streamlit-authenticator

Now we change our previous tutorial Streamlit page to this.

import pandas as pd
import streamlit as st
import streamlit_authenticator as stauth

names = ['Lewandowski','Hanafi Harron']
usernames = ['lewan','hanafi']
passwords = ['mth107','mth108']

hashed_passwords = stauth.hasher(passwords).generate()
authenticator = stauth.authenticate(names,usernames,hashed_passwords,
'AdLeS_cookie','AdLeS_key',cookie_expiry_days=30)

name, authentication_status = authenticator.login('Login','main')

if authentication_status:
  st.title('Welcome *%s* to Pakistan' % (name))
  st.write("Our first Streamlit App")

  st.write(
    pd.DataFrame({
      'A': [1, 2, 3, 4],
      'B': [5, 6, 7, 8]
	    })
	 )

elif authentication_status == False:
  st.error('Username/password is incorrect')
elif authentication_status == None:
  st.warning('Please enter your username and password')

Well it is all dandy but if you have a slightly complicated script you will soon see errors appearing but streamlit is in debug mode by default. So you have to disable it by modifying the config.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS