Hello everyone,
So i’ve developed an app using login streamlit authenticator. the password changes features did work on the codespace test run and also the live app when i log out and login with the new password but, it seems the password changes didn’t updated to the github config.yaml. After every wake up or when i’m done adding some pages and push it to the live app the password on config.yaml back to the previous password before the changes. is this a drawbacks from config.yaml or i did something wrong with the implementation?
Here is the code:
import streamlit as st
import streamlit_authenticator as stauth
import requests
import yaml
from yaml.loader import SafeLoader
from streamlit_authenticator.utilities import (CredentialsError,
ForgotError,
Hasher,
LoginError,
RegisterError,
ResetError,
UpdateError)
with open('config.yaml') as file:
config = yaml.load(file, Loader=SafeLoader)
# Pre-hashing all plain text passwords once
Hasher.hash_passwords(config['credentials'])
st.set_page_config(initial_sidebar_state="collapsed")
authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['pre-authorized']
)
authenticator.login()
if st.session_state['authentication_status']:
st.sidebar.success(f'Welcome *{st.session_state["name"]}*')
st.title('Change password and update name & email')
if st.session_state['authentication_status']:
try:
if authenticator.reset_password(st.session_state["username"]):
st.success('Password modified successfully')
with open('../config.yaml', 'w') as file:
yaml.dump(config, file, default_flow_style=False)
except ResetError as e:
st.error(e)
st.error('Password must contain A-Z, a-z, 0-9, @$!%*?&, minimum 8-20 Character')
except CredentialsError as e:
st.error(e)
if st.session_state['authentication_status']:
try:
if authenticator.update_user_details(st.session_state["username"]):
st.success('Entries updated successfully')
with open('../config.yaml', 'w') as file:
yaml.dump(config, file, default_flow_style=False)
except UpdateError as e:
st.error(e)
authenticator.logout('Logout','sidebar')
elif st.session_state['authentication_status'] is False:
st.markdown(
"""
<style>
[data-testid="collapsedControl"] {
display: none
}
</style>
""",
unsafe_allow_html=True,
)
st.error('Username/password is incorrect')
elif st.session_state['authentication_status'] is None:
st.markdown(
"""
<style>
[data-testid="collapsedControl"] {
display: none
}
</style>
""",
unsafe_allow_html=True,
)
st.warning('Please enter your username and password')
with open('config.yaml', 'w') as file:
yaml.dump(config, file, default_flow_style=False)