DEV Community

Cover image for Elastic D&D - Update 15 - Fixing Password Reset
Joe
Joe

Posted on • Updated on

Elastic D&D - Update 15 - Fixing Password Reset

In the last post we talked about how rewriting the Note Input. If you missed it, you can check that out here!

Fixing Password Reset

I finally gave access to my project to my D&D group! This would have been exciting, except when they all went to reset their passwords from "changeme", there were some issues. Specifically, the update_yml function wasn't able to locate the "config" variable.

Old code:

def update_yml():
    # updates login authentication configuration file
    with open(streamlit_project_path + "auth.yml", 'w') as file:
        yaml.dump(config, file, default_flow_style=False)
Enter fullscreen mode Exit fullscreen mode

Now, I should have realized this, but this function wasn't able to grab the variable from outside of the function. I made this change to pass the configuration into the function and it works now.

New code:

def update_yml(updated_config):
    # updates login authentication configuration file
    with open(streamlit_project_path + "auth.yml", 'w') as file:
        yaml.dump(updated_config, file, default_flow_style=False)
Enter fullscreen mode Exit fullscreen mode

NOTE:

I felt really dumb once I realized what was happening. I legitimately couldn't figure out what was wrong and had to sleep off the frustration in order to spot this. Saying that to say, silly mistakes happen sometimes and that's okay.

Logon Issue

Funnily enough, while I was troubleshooting the YAML issue, I noticed that users could still log in even if they put in an incorrect password. This shouldn't have been the case, and it ended up being a logic issue in the code.

See, when inputting an incorrect password, the username field was still being populated, which bypassed my check in the code:

if not st.session_state.username:
    DISPLAY LOGON WIDGET
else:
    DISPLAY HOME PAGE
Enter fullscreen mode Exit fullscreen mode

Now, we initialize the authentication status along with the username, as well as check that instead of the username:

initialize_session_state(["username","authentication_status"])
...
if st.session_state.authentication_status in (False,None):
    DISPLAY LOGON WIDGET
else:
    DISPLAY HOME PAGE
Enter fullscreen mode Exit fullscreen mode

Closing Remarks

I'm glad I was able to identify the faulty parts of both of these issues. The program as a whole functions better with these changes in place. This is a friendly reminder to tell me about issues that you come across via Github. I will get to them!

I will be taking next week off for the holidays, but work on the player dashboard will begin soon after!

Check out the GitHub repo below. You can also find my Twitch account in the socials link, where I will be actively working on this during the week while interacting with whoever is hanging out!

GitHub Repo
Socials

Happy Coding,
Joe

Top comments (0)