Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to store database password

Tags:

c#

passwords

I am sure there're lots of discussions already, but how to store a password in an application? (I meant not a user password to be stored in a table in a database, but the password to build connection string)

I've seen suggestions like store it encrypted in a flat file such as xml file, then read it +decrypt it at run time. If this application runs on a server, this is a very good choice, but what if the application will be deployed to end-users' pc? i.e. the flat file will be copied to the user's pc. Is this still a good practice? (my instinct is 'NO')

I know the existence of SecurityString, but then I also read in one post that SecurityString can be easily broken into, too.

Is it a good idea to use Password Vault that comes with Windows 7? Is there any good example of utilizing it programmatically? I've seen an example in msdn, but firstly it is labeled with 'windows 8', secondly when I downloaded the files and opened the solution in visual studio 2012 EXPRESS, it failed to open.

Any suggestion is welcome...many thanks.

--update--

Let's say, the application will be running on a handful of PCs within a windows domain. (1) At start-up, the application will do a LDAP authentication (active directory). Only upon successful authentication, the application will carry on, and (2) behind the scene the app can connect to the database, take user input to query the db, and this is where the db passwd comes into the play to build the connection string (no this is not SQL SERVER database so I don't think the option of using windows authentication is viable, unless a commercial plug-in is used).

The db resides in the same domain, and has been set up to allow certain range of IP addresses, and is SSL enabled. In short, it is quite secure in this sense. The only bit that is not yet secure is how to store the db passwd for the application.

What caught my eye was the Mysql Workbench. It will save db connections, including the password - which is stored in a password vault. That is mysql's own implementation of a password vault, and I am very curious as to how it is done.

like image 873
user1866880 Avatar asked Dec 11 '12 16:12

user1866880


2 Answers

There is no way to give a password to your users and expect it to remain safe. Even if it is hidden in your compiled application and hashed with a one way hash, the determined will recover it.

Instead you should consider your security architecture.

If you are providing services which your application connects to then you should look at providing some sort of more robust authentication as part of your public API.

If the connection string is for connecting to another part of the distributed software, then you should make the password configurable by the end user and store it in a keyring or other encrypted storage.

-- Update --

It looks like this might be what you are looking for;

http://www.microsoft.com/indonesia/msdn/credmgmt.aspx

like image 94
Morgan Borman Avatar answered Oct 05 '22 10:10

Morgan Borman


If the application is going to be deployed where you have no or little control over the system security, ie, external user pc, then it may be worth creating a user login. Authenticate the user against this login, and then from a relatively secure server use whatever credentials you need to provide data.

This does not guarantee security, but it will be easier to maintain if you need to change the password at some point in the future, or if an individual user is compromised.

like image 31
Kami Avatar answered Oct 05 '22 08:10

Kami