tmrhmdv
tmrhmdv

Reputation: 172

Hiding MySQL credentials in a C# app

I am extending an open-source VoIP softphone application (written in C#/.NET) to my needs but don't know how to best approach this issue. I want the application to connect to database when a user enters his email address to log in, and perform a SQL query to fetch his account number using that email and authenticate with account number. But, I think including my MySQL connection credentials (host, username, database) is insecure? How should I do it?

Upvotes: 2

Views: 2632

Answers (7)

Vladislav Zorov
Vladislav Zorov

Reputation: 3046

It is indeed insecure.

You need software running on the server, that can accept said email and password as input and connect to your database (so the connection string is sitting on a machine in your control), check it and return either ACCEPTED or DENIED to the client. In your case, ACCEPTED could be just the account number you mention.

Bonus points if the email and password are transmitted from client to server app over an encrypted link (public key).

Upvotes: 2

Pheonix
Pheonix

Reputation: 6052

You should host a (php/jsp/asp) script at your server with which your application will talk. you should not store your credentials inside the app at any cost.

Tthere are so many ways to just take out the information. Especially .NET applications. it doesn't takes more that 30 mins :p

Upvotes: 0

competent_tech
competent_tech

Reputation: 44931

Our rule of thumb when designing database applications is to always use delegation and isolation.

What isolation means is that we isolate database interaction from the end user application through the use of services (i.e. web services, wcf, .net remoting, etc). In this way, the database is never directly exposed to the user.

What delegation means is that the database access is always performed on behalf of the end user by a well-known, limited-access database user (generally the user that the service is running as). If at all possible, the database access should be performed by a user authenticated by the network rather than by storing user names and passwords in connection strings or other semi-secure locations.

Finally, one important note: you should always encrypt your end-user's login and password information before sending it over the wire. This is a little extra work, but well worth it from a security perspective.

Upvotes: 1

Cameron S
Cameron S

Reputation: 2301

There are many ways to do it, including obfuscation and other ways making it difficult to use outside of the application, but not impossible to retrieve/use.

How should you do it? The best way (as far as I know) is to give the account the minimum credentials necessary so that if someone does have the username and password he/she cannot do anything malicious with it. Permissions can be set up in many ways for user-specific data, such as views so a user can only access the correct rows. Basically, if security is a top concern, assign permissions conservatively and if necessary give different users different credentials.

Upvotes: 0

JOpuckman
JOpuckman

Reputation: 1376

You could code your connection strings so that they end up in your assembly and use a code obfuscator to protect it from disassemblers

Upvotes: 0

Roman
Roman

Reputation: 20246

You should put the connection strings into a configuration file and then encrypt that portion of the file. There's a tutorial on how to do that here: Protecting Connection Strings and Other Configuration Information. Although the tutorial is for ASP.NET, the same principle will apply to pretty much any .NET config file.

There's also a similar question here: Encrypting passwords in WinForms app.config, .NET.

Upvotes: 1

Jared Peless
Jared Peless

Reputation: 1120

Can MySQL do Windows based authentication (i.e. on a domain)? If so, you could use that. Otherwise you might want to have credentials to a service, or use encryption, but you would need to include the encryption key so anyone dedicated to discovering it would.

Upvotes: 0

Related Questions