Connect database in dash_auth.BasicAuth

Hi,

How to connect the database (which stored the username and password) and able to get from the dash_auth.BasicAuth?

Normally, the username and password will be stored in VALID_USERNAME_PASSWORD_PAIRS and connect as per below:

VALID_USERNAME_PASSWORD_PAIRS = {
                                'user': 'pwd',
                                'usera': 'pwd1'

                                    }

auth = dash_auth.BasicAuth(app, VALID_USERNAME_PASSWORD_PAIRS)

If let say currently all the username and password is stored in a database, can I use the same way dash_auth.BasicAuth to connect? How to do?

Or any other method I can connect the database to get the user login access?

Hello @beginof,

You can connect to your database and perform your query to get your usernames and passwords as a pandas dataframe. Once you do that, you can convert the dataframe to a dictionary of username:passwords by:

VALID_USERNAME_PASSWORD_PAIRS = df.set_index(‘username’)[‘password’].to_dict()

For this to work, you’ll have to have unique usernames.

Hi @jinnyzor

Thanks your solution.