Closed jitvimol closed 1 year ago
Can you please provide a snippet of your code?
Can you please provide a snippet of your code?
Sure Thanks for the help:
I simply add function to reset pwd right after user successfully log in and test logging out.
import streamlit as st
import streamlit_authenticator as stauth
import yaml
from yaml import SafeLoader
with open('config.yaml') as file:
config = yaml.load(file, Loader=SafeLoader)
authenticator = stauth.authenticate.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['preauthorized']
)
name, authentication_status, username = authenticator.login('Login', 'main')
if st.session_state["authentication_status"]:
authenticator.logout('Logout', 'main')
st.title(f'Welcome *{st.session_state["name"]}*')
if authentication_status:
try:
if authenticator.update_user_details(username, 'Update user details'):
st.success('Entries updated successfully')
except Exception as e:
st.error(e)
elif st.session_state["authentication_status"] == False:
st.error('Username/password is incorrect')
elif st.session_state["authentication_status"] == None:
st.warning('Please enter your username and password')
Pleas refer to point 9 of the readme file, once you have updated the config file on memory, you must then commit it to disk.
Pleas refer to point 9 of the readme file, once you have updated the config file on memory, you must then commit it to disk.
Thank you very much. Apologize for not fully understand the library.
import streamlit as st import streamlit_authenticator as stauth import yaml from yaml import SafeLoader with open('config.yaml') as file: config = yaml.load(file, Loader=SafeLoader) authenticator = stauth.authenticate.Authenticate( config['credentials'], config['cookie']['name'], config['cookie']['key'], config['cookie']['expiry_days'], config['preauthorized'] ) name, authentication_status, username = authenticator.login('Login', 'main') if st.session_state["authentication_status"]: authenticator.logout('Logout', 'main') st.title(f'Welcome *{st.session_state["name"]}*') if authentication_status: try: if authenticator.update_user_details(username, 'Update user details'): st.success('Entries updated successfully') except Exception as e: st.error(e) elif st.session_state["authentication_status"] == False: st.error('Username/password is incorrect') elif st.session_state["authentication_status"] == None: st.warning('Please enter your username and password')
@jitvimol Where did you insert the code from the readme that updates
config.yaml
within the above code snippet? I'm having trouble implementing this functionality in my streamlit app.
Here is the snippet that saves your changes:
with open('../config.yaml', 'w') as file:
yaml.dump(config, file, default_flow_style=False)
When user edit password, it seems to store new pwd in memory. If user log out, he cannot log in with newly created pwd.