Reputation: 36311
So I am building a GUI for connecting to MySQL databases, and I have a window where users can enter in: Host
, User
, Password
, Port
and a Connection Name
. I would like to save connection information for multiple MySQL database connections.
I want Connection Name
to be a unique name and when someone opens the main screen to the application there is a list of previously saved connections. When the user clicks on one of the Connection Names
it will connect to the database. And they can then run queries.
What I would like to know is, what would be the best way to save these connections?
In my opinion, Saving in a flat file just doesn't sound like a safe way to do this.
Upvotes: 1
Views: 230
Reputation: 11040
If your users have login/password you can use their password to encrypt the connections data.
If they don't (they should!) then your best option depends on the OS: Keychain API in OSX or DPAPI in Windows, I don't know about Linux but it probably has an equivalent API.
And you are correct: it's a horrible idea to put the connection info in a plaintext file
Upvotes: 1
Reputation: 18614
You may encrypt the data with user's password. Don't forget to re-encrypt on password change. This is not the case here but if you have large data to encrypt/decrypt, you can have a statuc key for data but ecrypt key with user password.
There are a lot of solutions to securely store passwords for the desktop but I'm not aware if any of them have java bindings.
Upvotes: 1