Streamlit Authentication widget reset password

Summary

How to display error message when new password does not match with repeat password using streamlit authenticator widget?

Steps to reproduce

Code snippet:

if authenticator.reset_password(username, 'Reset password'):
            st.success('Password modified successfully')

The above code resets the password if we enter new password and repeat password as same, but the widget just dissapears without displaying any error if the two passwords do not match. How can I fix this?

Expected behavior:

I expect the program to show an error message as- “New password and Repeat password does not match, please try again”

Actual behavior:

The widget entirely dissapears without letting the users know that the password could not be reset. This does not reset the password.

Reference

Check out this blog for code on authenticator widget.

Question

Can someone help me fix the issue?

Hey @rahulrama,

I’m not an expert on that component, but it looks like this logic is implemented in line 277 of this file.

   if reset_password_form.form_submit_button('Reset'):
            if self._check_credentials(inplace=False):
                if len(new_password) > 0:
                    if new_password == new_password_repeat:
                        if self.password != new_password: 
                            self._update_password(self.username, new_password)
                            return True
                        else:
                            raise ResetError('New and current passwords are the same')
                    else:
                        raise ResetError('Passwords do not match')
                else:
                    raise ResetError('No new password provided')
            else:
                raise CredentialsError
    

Hello Caroline, I’ve another question about password resets.
This is my code for the widget:
Where will the new password be sent to? Is it via email? Cos i can’t seem to find it! thank you so much!

    username_of_forgotten_password, email_of_forgotten_password, new_random_password = authenticator.forgot_password('Reset password here')
    
    if username_of_forgotten_password:
        st.success('New password sent securely')

Oh I figured it out! It returns the parameter of new_random_password and its up to me on how I want to securely transfer it to the user or just have it simply written in the next line.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.