Example here QGIS v3.40 Bratislava
Opening projects in QGIS can result in multiple and continual requests to authenticate every database connected to a project. This gets old quickly. You will be glad to know that you can save the connections to the project file. Be aware that Username and Password is saved into the project file. It should be noted that v3.40 which I am using comes with a master password option – this will act as a gate keeper for all of your connection strings should you choose to save them – at present I have all of these tied to a QGIS master password.
In theory saving passwords with projects could introduce a security risk although its pretty small! Generally I would always recommend that you whitelist IPs or Domains at the database server level such that connections that are not whitelisted will not be able to connect. This is one of the easiest bullet proof ways of improving security. The first thing I do when I create a database even if it is not particularly sensitive is setup a white list. To date I have done this through the Web Hosting Management Software – cpanel / Azure etc.. It is highly likely if you are in an organisation this is already in place.

Go to Layer / Add Layer / PostGIS Connection
And within the Data Source Manager : PostgreSQL hit the Edit button on the drop down you are interested in saving credentials against and within the Authentication sub form select Basic and fill out Username and Password and ensure Store is ticked then trigger Convert to configuration.

Configuration should now be written to the project WHICH YOU MUST NOW SAVE and Authentication Configuarations tab should show status of the save

Now when you go into the project for this connection you should not be prompted for details.