Feature request #6239
Get username and password from qgis environment
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | - | ||
Category: | - | ||
Pull Request or Patch supplied: | No | Resolution: | invalid |
Easy fix?: | No | Copied to github as #: | 15547 |
Description
I'm trying to get this code to work:
dbConnection = QgsDataSourceURI(iface.activeLayer().dataProvider().dataSourceUri())
db = QSqlDatabase.addDatabase("QPSQL")
db.setHostName(dbConnection.host())
db.setDatabaseName(dbConnection.database())
db.setUserName(dbConnection.username())
db.setPassword(dbConnection.password())
db.setPort(int(dbConnection.port()))
but the problem is that this uses the data on the .qgs file, and not the environment one.
The username and password are grabber from the .qgs project file, but we would like to get it from the environment (because we don't whant to put this sensitive data on the .qgs file).
Is there any way to get this from the environment? (From the data that the user typed when the project loads)
Best regards.
History
#1 Updated by Nathan Woodrow about 12 years ago
- Resolution set to invalid
- Status changed from Open to Closed
This is not really a bug and should be posted on the mailing list.
#2 Updated by cremat0rio - about 12 years ago
I've defined as a feature request.
As there seems to be no class to do this.
#3 Updated by Nathan Woodrow about 12 years ago
Sorry I might have been a bit fast on the close.
Can't you use:
import getpass username = getpass.getuser()
I'm not even sure if you can gepassword via something like that, or it would be just as much a risk.
#4 Updated by Jürgen Fischer about 12 years ago
checkout QgsCredentials (example usage: qgspostgresconn.cpp:172)
#5 Updated by cremat0rio - about 12 years ago
getpass.getuser() -> works, getting the username
getpass.getpass() -> blocks qgis (http://docs.python.org/library/getpass.html says it will get pass from stdin)
QgsCredentials (QgsCredentialDialog) seams to ask the user for his password, which has already been done when the project opened.
Isn't there a way to get those already gotten credentials?