I'm fairly certain this should be a community wiki, but I don't know how to make it one. So if an admin sees this please change if appropriate.

So... how do you protect your PostGIS database data when using QGIS 1.7? (I am using QGIS 1.7 and PostGIS 1.5)

The reason I ask is that I opened a QGIS project file in notepad++ to alter the host value in my datasource string as we recently had a server change its name. When I was editing the project file in notepad++ I saw plain as day the user name and password to the database like shown below.

 <datasource>dbname='spatialdb' host=gis port=9999 user='generaluser' 
              password='gisv13wer' sslmode=disable key='gid' 
              table="gisprod"."aq_pipeline" (the_geom) sql=</datasource>

This does seem to be somewhat of a double edged sword because I like the fact that I could easily edit the host value in my datasource string so that I didn't lose my projects, but I am uncomfortable with the fact that the database credentials are sitting there unencrypted and for the world to see so to speak.

As a contingency I've placed all my project files which use my admin account into a folder which now only I can access. But I don't think this is ideal.

As the GIS Administrator I am responsible for the spatial databases integrity and I am concern that I have just exposed my whole database to anyone who is curious enough to get in. I'm a bit bummed I missed this when we were evaluating QGIS.

So how do you manage this risk if you are in a similar situation? Is my contingency good enough for a production environment or would I be better off putting in a QGIS feature request to address the problem?

  • Also applies to workplaces where QGIS projects are shared.
    – raphael
    Jan 30, 2017 at 18:58

2 Answers 2


Don't check "Save passwords" (and/or "Save username") in the connection - and QGIS will ask for credentials when it needs them.

  • Great - I can't believe I overlooked this. I was somewhat flabbergasted when I looked in the project file and popped a panicked post on here.
    – Ando
    Jun 20, 2012 at 5:23

It is possible to manually delete attributes from the project file such as the user & password attributes. In your example, you could use Find & Replace to delete every instance of "user='generaluser' password='gisv13wer'".

However, if you add another layer while QGIS is set to remember the credentials, the credentials will once again be embedded into the project file.

The best advice would be follow jef's solution and disable saving of the Username & Password.

You may however have to manually delete the user credentials from existing project files if QGIS does not remove them after resaving the project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.