mkhorasani / Streamlit-Authenticator

A secure authentication module to manage user access in a Streamlit application.
Other
1.56k stars 248 forks source link

hashed password can be saved and loaded as file #11

Closed aduverger closed 2 years ago

aduverger commented 2 years ago

This PR is related to issue https://github.com/mkhorasani/Streamlit-Authenticator/issues/9

This implements the possibility to automatically save the hashed_passwords as a file (with the .generate method), and load it (with the .Authenticate method).

The workflow looks like this:

names = ['John Smith', 'Rebecca Briggs']
usernames = ['jsmith', 'rbriggs']
passwords = ['123', '456']

hashed_passwords = stauth.Hasher(passwords).generate(folder_path="path_to_folder")

A .key file is then automatically generated at path_to_folder/hashed_passwords1546.key 1546 here is a random number generated when .Hasher.generate() is called.

Then, when you need to use hashed_passwords, you can use the legacy way with hashed_passwords being a list:

authenticator = stauth.Authenticate(
    names, usernames, hashed_passwords,
    'some_cookie_name',  'some_signature_key', cookie_expiry_days=30,
)

Or you can alternatively use the saved hashed_passwords1546.key file:

authenticator = stauth.Authenticate(
    names, usernames,"path_to_folder/hashed_passwords1546.key",
    'some_cookie_name', 'some_signature_key', cookie_expiry_days=30
)

Signed-off-by: Alexandre Duverger alexandre.duverger@solution-bi.com