Hello everyone,
I’m having troubles with the reset_password widget: it doesn’t seem to update the config file with user’s credentials.
Please chek my code below: “DEBUG 1” and “DEBUG 2” prints are the same, even after I fill up the reset_passwords form and hit the “Reset” button.
If I push the “Reset” button twice, the second time I get the error “Password is not correct” (which is true, since I’ve just updated it) but the config file (./config/auth.yaml) is not updated, so if I log out and want to login again, I have to use the old password.
I think I’m not using properly the “step 9” of the README file from github but… what is the correct way, since the ‘config’ variable content doesn’t change after the password has been reset?
ps.
DEBUG 3 prints (among other stuff) this:
“FormSubmitter:Reset password-Reset”: true
Here is my code:
import streamlit as st
import streamlit_authenticator as stauth
import yaml
from yaml.loader import SafeLoader
with open('./config/auth.yaml') as file:
config = yaml.load(file, Loader=SafeLoader)
st.write(config) # DEBUG 1
authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['pre-authorized']
)
authenticator.login()
if "authenticator" not in st.session_state:
st.session_state["authenticator"] = authenticator
if st.session_state["authentication_status"] == False:
st.error("Wrong username or password")
elif st.session_state["authentication_status"] == None:
st.warning("Please insert your credentials")
elif st.session_state["authentication_status"]:
if "loggedIn" not in st.session_state:
st.session_state["loggedIn"] = True
try:
if st.session_state["authenticator"].reset_password(st.session_state["username"]):
st.success('Password modified successfully')
except Exception as e:
st.error(e)
st.write(config) # DEBUG 2
st.write(st.session_state) # DEBUG 3
with open('./config/auth.yaml', 'w') as file:
yaml.dump(config, file, default_flow_style=False)