I wrote the code below, but I need that the PostGIS connection to be verified, to be sure that the username and password are right. I tried this: How to access user credentials in database connection? , but it didn't worked.
I am using QGIS 3.8.3
uri = QgsDataSourceUri() uri.setConnection('LPOSTDES-CL2', '5432', 'ugpi', None, None) connInfo = uri.connectionInfo() (success ,user, passwd) = QgsCredentials.instance().get(connInfo, None, None) if success: QgsCredentials.instance().put(connInfo, user, passwd) uri.setConnection('LPOSTDES-CL2', '5432', 'ugpi', user, passwd)