Streamlit Authentication very NOOB question

Very, very noob question and im sorry for it.
How to implement it ?

pip install streamlit-authenticator

import streamlit as st
import streamlit_authenticator as stauth

Easy.

Next step.

1. Hashing passwords

Initially create a YAML configuration file .....
Ok. lets say we create auth.yaml

Then we add credentials like example shows.

But what about next ? This is where im utterly lost.

  • Then use the Hasher module to convert the plain text passwords into hashed passwords.
    hashed_passwords = stauth.Hasher(['abc', 'def']).generate()

What hasher ? where is it ? how to use it ?
With older versions i just have

gen_keys.py file

import pickle
from pathlib import Path
import streamlit_authenticator as stauth

names = ["Demo"]
usernames = ["Demo"]
passwords = ["pas123"]

hashed_passwords = stauth.Hasher(passwords).generate()

file_path = Path(__file__).parent / "hashed_pwd.pkl"
with file_path.open("wb") as file:
    pickle.dump(hashed_passwords, file)

and i just run python gen_keys.py run

Then is this step:

2. Creating a login widget

  • Subsequently import the configuration file into your script and create an authentication object.

import yaml
from yaml.loader import SafeLoader

Is this inside streamlit app ?

My current streamlit app looks like this:

import streamlit as st
import streamlit_authenticator as stauth

# User auth.
names = ["Demo"]
username = ["demo"]
# Load hashed passwords
file_path = Path(__file__).parent / "hashed_pwd.pkl"
with file_path.open("rb") as file:
    hashed_passwords = pickle.load(file)

authenticator = stauth.Authenticate(names, usernames, hashed_passwords, "dashboard", "prototype", cookie_expiry_days=30)

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

Basically i dont understand Step 1 and Step 2
Thank You.

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