The approach above by @nth-attempt worked quite well for me, thanks!
Minor suggestion: instead of
else:
    st.error("the password you entered is incorrect")

I would do elif session_state.password != '', so that the error doesn’t show up when the password is blank!