tags:

views:

290

answers:

4

Hi,

I have a situation that users access remote MySQL server in C# application.

Basically,

A user using C# application on his/her desktop ->>>> connects to remote ->>>>>>>> [ REMOTE ]

How do I securely hide database connection detail?

I have few ideas, but I don't think they are safe.

  1. Encrypt database connection data into a file and store it within application directory.
  2. prompt login page and let a human enter username/password, then transfer database connection data to user's computer.
+5  A: 

No matter what you do if the credentials end up in the application in cleartext you are vulnerable.

Either implement a service layer in front of the database or if direct connections are essential try and come up with a scheme that allows a unique databse account for each user and then authorise them appropriately on the database.

sipwiz
Service layer +1
James Bailey
+1 for service layer.
Glenn Condron
+3  A: 

Generally, it's better to ask the user for the credentials so that each account can be enabled or disabled by the administrator. Barring that, there are APIs for encrypting all or part of the configuration file. Here's a sample article:

http://www.codeproject.com/KB/dotnet/EncryptingTheAppConfig.aspx

James Bailey
Yes, ask the user.
jeffamaphone
+1 Use system.configuration.configurationmanager with an encrypted connection string. Or unique credentials.
J.Hendrix
A: 

I would suggest some form of session management based on user credentials. This can be accomplished in many ways.

For instance, you may accomplish this by simply wrapping your database access with a back-end system. Your desktop clients are oblivious to the database and interact solely with the back-end system. Unfortunately, implementing this level of indirection is not trivial if you have to do it from scratch but it will certainly make your application more robust and flexible. WCF services can help accomplish this.

Newbie
I missed sipwiz answer. It is pretty much the same as this one.
Newbie