Password Protect QGIS project

Your best bet is going to be not saving the db credentials in your project (QGIS even gives you a warning on the potential danger of saving your credentials when you first add the db).

When you open the project, you'll immediately be prompted for your credentials before any layers from the db are rendered.

Alternatively, you can:

  • Use OS methods to hide/protect the directory where your QGIS project is stored, ie only your user account can access that particular directory
  • You could try your hand at running a Python script on project open that might ask for credentials, though in the 5 minutes I spent trying that, could not get this to work. Check out Project Properties (CTRL+Shift+P) and then Macros to see what I mean.

To follow up on the danger of saving your db credentials in QGIS, see this question. It's trivial for anyone with the slightest curiosity to see your credentials in plain text.


There was a similar question I answered here. I didn't go too far into setting up an idea on how to create the login form, although much of a logic is there.

If you can trust your users not to try to get into your python code (or compile to an .exe to make it even harder), you could create a script that will either open up the project with the layers loaded in it, or an empty project if they are unable to supply the correct credentials.

There was talk of checking the information against a server for a more secure method, which you could implement in your Postgres/PostGIS instance. You could find as a more simple stopgap to code in your user name and a hashed password into your python code that feeds to an API for verification. So let your server do the comparison instead of your desktop code. Storing your hashed password locally isn't the most secure way of doing things, but depending on your hash algorithm, it could potentially be pretty difficult to crack it.

Ultimately, it is probably more secure to just supply your credentials every time unless you know the other users aren't computer savvy enough to figure out any of the automated methods you'd supply.