Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newly created pwd from function reset_password doesn't update new pwd in config.ymal #29

Closed
jitvimol opened this issue Aug 24, 2022 · 6 comments

Comments

@jitvimol
Copy link

When user edit password, it seems to store new pwd in memory. If user log out, he cannot log in with newly created pwd.

@mkhorasani
Copy link
Owner

Can you please provide a snippet of your code?

@jitvimol
Copy link
Author

jitvimol commented Aug 24, 2022

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')

@mkhorasani
Copy link
Owner

mkhorasani commented Aug 24, 2022

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.

@jitvimol
Copy link
Author

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.

@colelandolt
Copy link

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.

@mkhorasani
Copy link
Owner

Here is the snippet that saves your changes:

with open('../config.yaml', 'w') as file:
    yaml.dump(config, file, default_flow_style=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants