PDA

View Full Version : How to save credentials in local keychain



kalos80
8th November 2010, 16:03
Hi,

In my application the user may need to provide username and password to access some remote machines... I would like to allow the user to load/restore those credentials.

For example in Mac machines I can see some application save/load passwords in/from local keychain. Does Qt provides any generic way to do it?

Thanks in advance for you hints.

wysota
8th November 2010, 16:06
You can store persistant data using QSettings.

kalos80
8th November 2010, 16:23
QSettings allows to store generic data... What if I want to save passwords?
In theory I need to encrypt them before saving, I also need to provide a encryption key and so on.

On Mac all passwords are saved in the keychain the user can access providing his system password. I have seen something similar in some Linux distribution too.
I was wondering whether Qt provides a generic way to do that, platform independent.

wysota
9th November 2010, 10:34
QSettings allows to store generic data... What if I want to save passwords?
In theory I need to encrypt them before saving, I also need to provide a encryption key and so on.
So encrypt it and store it in QSettings.


On Mac all passwords are saved in the keychain the user can access providing his system password. I have seen something similar in some Linux distribution too.
You can easily attach to those keychains using native API.

I was wondering whether Qt provides a generic way to do that, platform independent.
No, there are too many solutions to handle them all. For instance on Linux you might be using KDE or GNOME or neither and (probably) each has own wallet implementation. You might want to take a look at PolicyKit though, there is probably a PolicyKit interface available for different password storage mechanisms on Unix. It might be simpler to store passwords using QSettings or encrypted local SQLite database though :)

kalos80
9th November 2010, 11:08
wysota,
thank you very much for your advices, they are very useful