mkhorasani / Streamlit-Authenticator

A secure authentication module to validate user credentials in a Streamlit application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

reset password error

ebynapura opened this issue · comments

when i reset the password, fill the new pw, and press the 'reset' button, but an error warning like:
'Authenticate' object has no attribute 'max_concurrent_users'
i don't understand why

@ebynapura can you please elaborate by providing a snippet of your code and specify the version of Streamlit-Authenticator you are using?

@ebynapura can you please elaborate by providing a snippet of your code and specify the version of Streamlit-Authenticator you are using?

import streamlit as st
import streamlit_authenticator as stauth
# from streamlit_authenticator import Authenticate
import yaml
from yaml.loader import SafeLoader

st.set_page_config(
   page_title="Acg-DataBoard",
   page_icon="data1.svg",
   layout="wide",
   initial_sidebar_state="collapsed",  # expanded auto
)

# Import the YAML file into your script
with open('config.yaml') as file:
    config = yaml.load(file, Loader=SafeLoader)


hashed_passwords = stauth.Hasher(['000000', '000000']).generate()
# print(hashed_passwords)

# Create the authenticator object
authenticator = stauth.Authenticate(
    config['credentials'],
    config['cookie']['name'],
    config['cookie']['key'],
    config['cookie']['expiry_days'],
    config['preauthorized']
)


if st.session_state["authentication_status"]:
    authenticator.logout(button_name='退出账户', location='sidebar')
    try:
        if authenticator.reset_password(st.session_state["username"], location='sidebar',
                                        fields={'Form name':'重设密码', 'Current password':'当前密码', 
                                                'New password':'新密码', 'Repeat password': '确认新密码', 'Reset':'重设'}):
            with open('config.yaml', 'w') as file:
                yaml.dump(config, file, default_flow_style=False)
            st.success("已成功修改密码~")
    except Exception as e:
        st.error(e)

    try:
        if authenticator.update_user_details(st.session_state["username"], location='sidebar', 
                                             fields={'Form name':'更新用户信息', 'Field':'更新项', 'Name':'姓名', 
                                                     'Email':'邮箱', 'New value':'更新为', 'Update':'更新'}):
            with open('config.yaml', 'w') as file:
                yaml.dump(config, file, default_flow_style=False)
            st.success('已成功修改信息~')
    except Exception as e:
        st.error(e)

    st.write(f'欢迎: *{st.session_state["name"]}*')
    st.title('Some content')
elif st.session_state["authentication_status"] is False:
    st.error('用户名或密码不正确~')
elif st.session_state["authentication_status"] is None:
    st.warning('请输入您的用户名和密码~')
    authenticator.login(fields={'Form name': '登录'})

@ebynapura can you please elaborate by providing a snippet of your code and specify the version of Streamlit-Authenticator you are using?

import streamlit as st
import streamlit_authenticator as stauth
# from streamlit_authenticator import Authenticate
import yaml
from yaml.loader import SafeLoader

st.set_page_config(
   page_title="Acg-DataBoard",
   page_icon="data1.svg",
   layout="wide",
   initial_sidebar_state="collapsed",  # expanded auto
)

# Import the YAML file into your script
with open('config.yaml') as file:
    config = yaml.load(file, Loader=SafeLoader)


hashed_passwords = stauth.Hasher(['000000', '000000']).generate()
# print(hashed_passwords)

# Create the authenticator object
authenticator = stauth.Authenticate(
    config['credentials'],
    config['cookie']['name'],
    config['cookie']['key'],
    config['cookie']['expiry_days'],
    config['preauthorized']
)


if st.session_state["authentication_status"]:
    authenticator.logout(button_name='退出账户', location='sidebar')
    try:
        if authenticator.reset_password(st.session_state["username"], location='sidebar',
                                        fields={'Form name':'重设密码', 'Current password':'当前密码', 
                                                'New password':'新密码', 'Repeat password': '确认新密码', 'Reset':'重设'}):
            with open('config.yaml', 'w') as file:
                yaml.dump(config, file, default_flow_style=False)
            st.success("已成功修改密码~")
    except Exception as e:
        st.error(e)

    try:
        if authenticator.update_user_details(st.session_state["username"], location='sidebar', 
                                             fields={'Form name':'更新用户信息', 'Field':'更新项', 'Name':'姓名', 
                                                     'Email':'邮箱', 'New value':'更新为', 'Update':'更新'}):
            with open('config.yaml', 'w') as file:
                yaml.dump(config, file, default_flow_style=False)
            st.success('已成功修改信息~')
    except Exception as e:
        st.error(e)

    st.write(f'欢迎: *{st.session_state["name"]}*')
    st.title('Some content')
elif st.session_state["authentication_status"] is False:
    st.error('用户名或密码不正确~')
elif st.session_state["authentication_status"] is None:
    st.warning('请输入您的用户名和密码~')
    authenticator.login(fields={'Form name': '登录'})

Which version of Streamlit_authenticator are you using?

@ebynapura can you please elaborate by providing a snippet of your code and specify the version of Streamlit-Authenticator you are using?

Which version of Streamlit_authenticator are you using?

it's 0.3.1

Dear @ebynapura you have raised an interesting issue, while I would not consider this to be a bug per se, it is indeed an issue that I need to address. The problem is that if you do not invoke the login widget, the max_concurrent_users attribute will not defined, leading to errors for other methods in the class. For your case if you can try to use the login widget before you use the reset password widget. And in the meantime, I will try to push a new release to address this issue.

Dear @ebynapura you have raised an interesting issue, while I would not consider this to be a

ok thx~

I had the same issue when using the function authenticator.reset_password() on a second page of my app as I want my users to have a dedicated page to account management. Calling the authenticator.login() before the authenticator.reset_password() in the code of the second page fixed it for now. I am using streamlit v1.31.1 and streamlit-authenticator v0.3.1. Thank you for the streamlit-authenticator library.

Dear @ebynapura you have raised an interesting issue, while I would not consider this to be a bug per se, it is indeed an issue that I need to address. The problem is that if you do not invoke the login widget, the max_concurrent_users attribute will not defined, leading to errors for other methods in the class. For your case if you can try to use the login widget before you use the reset password widget. And in the meantime, I will try to push a new release to address this issue.

This is a issue, I can't implement the ability to reset my password right now, even after reusing the login component

Dear @ebynapura you have raised an interesting issue, while I would not consider this to be a bug per se, it is indeed an issue that I need to address. The problem is that if you do not invoke the login widget, the max_concurrent_users attribute will not defined, leading to errors for other methods in the class. For your case if you can try to use the login widget before you use the reset password widget. And in the meantime, I will try to push a new release to address this issue.

When will this be fixed?

Apologies for the delay, will try to release a new version this weekend.

Apologies for the delay, will try to release a new version this weekend.

Oh, fantastic, looking forward to this fix! I am also getting the same error and the suggestions above did not resolve it... Thank you for this library!

Dear all this issue has now been fixed in v0.3.2. Thank you for your patience.