Using the stauth.Authenticate class in my Python(Streamlit) code is giving me trouble.The issue seems to be related to case sensitivity in dictionary keys. I have a set of user credentials retrieved from a database, and I'm constructing a dictionary to use with the stauth.Authenticate class. However, after creating an instance of the class, the keys in the dictionary are converted to lowercase. Here is a simplified version of my code:
user_names = run_query("SELECT tbl_acl.user FROM tbl_acl")
# Converting to List
user_names_list = [item[0] for item in user_names]
names = run_query("SELECT last_name FROM tbl_acl")
names_list = [item[0] for item in names]
passwords = run_query("SELECT password FROM tbl_acl")
passwords_list = [item[0] for item in passwords]
hashed_passwords = stauth.Hasher(passwords_list).generate()
credentials = {"usernames": {}}
for un, name, pw in zip(user_names_list, names, hashed_passwords):
user_dict = {"name": name, "password": pw}
credentials["usernames"].update({un: user_dict})
print(credentials)
authenticator = stauth.Authenticate(
credentials, "some_cookie_name", "some_signature_key", cookie_expiry_days=30
)
print(credentials)
In the printed credentials dictionary, the keys originally had mixed cases ( 'AbduL', 'AwaL','NadiM'), but after using the stauth.Authenticate class, the keys are converted to lowercase ('abdul', 'awal','nadim'). I have reviewed the documentation for the stauth library, but I couldn't find information about this behavior.
1st --> print(credentials)
{'usernames': {'AbduL': {'name': (None,), 'password': '$2b$12$GM50VYr7Bu3Ve7JKcPGxN.ApmzXSDaYjU8/kQlW9OXK00ZMFa5oa'}, 'AwaL': {'name': ('',), 'password': '$2b$12$UtcGY0HUPzXtflFHXlbsee3UbekPXMSyPKLPUOVMBlT4qgAIe1BP6'}, 'NadiM': {'name': (None,), 'password': '$2b$12$n5DY/I.i4xVQxIgqsLbmLe8iSrn/9TLfnkCJ.7MbJdjpj8JO3etW'}}}
2nd --> print(credentials)
{'usernames':{'abdul': {'name': (None,), 'password': '$2b$12$GM50VYr7Bu3Ve7JKcPGxN.ApmzXSD0ajU8/kQlW9OXK00ZMFa5oa'}, 'awal': {'name': ('',), 'password': '$2b$12$UtcGY0HUPzXtflFHXlbsee3UbekPXSyPKLPUOVMBlT4qgAIe1BP6'}, 'nadim': {'name': (None,), 'password': '$2b$12$n5DY/I.i4xVQxIgqsLbmLe8iSrn9TJLfnkCJ.7MbJdjpj8JO3etW'}}}