mkhorasani / Streamlit-Authenticator

A secure authentication module to validate user credentials in a Streamlit application.
Apache License 2.0
1.38k stars 229 forks source link

The three-level credential dictionary is vey painful to use #36

Closed iFengZhao closed 1 year ago

iFengZhao commented 1 year ago

Hi @mkhorasani , thank you for sharing this amazing package with us. I found the new way of adding credentials very painful to use, especially for those who retrieve user information from a remote database. 1) I don't think it's a good idea to create a three-level credential dictionary. It takes the users extra work to convert the data they retrieved from the database to the format that meets the requirement. As you can see below, the 'usernames' key in the dictionary is useless. Also, the keys at the second level of the dictionary are the usernames. The varying keys at this level make it a lot more difficult to do certain operations {'usernames': {'jsmith': {'email': 'jsmith@gmail.com', 'name': 'John Smith', 'password': 123}, 'rbriggs': {'email': 'rbriggs@gmail.com', 'name': 'Rebecca Briggs', 'password': 456}}} Is there a specific reason for not using a much simpler structure like below? {'username': 'jsmith', 'email': 'jsmith@gmail.com', 'name': 'John Smith', 'password': 123}

2) the Hashing passwords part also became very difficult to use. Previously, we only needed to provide a list of hashed passwords to the Authenticator. Now, we need to first retrieve the original passwords from the very painful 3-level dictionary and then hash them and then put them back. It feels like torture.

mkhorasani commented 1 year ago

Hi @iFengZhao, you're most welcome.

In order to enforce unique usernames, I have no choice but to use a nested dictionary with this structure. I know it solicits more effort to wrangle with, but there is no other way to implement it.

If you want to access all the passwords in the nested credentials dictionary, you can use the following snippet:

passwords = []
for username in credentials['usernames'].keys():
   passwords.append(credentials['usernames'][username]['password'])