Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I safely store database login and password in a C# application?

I have a C# application that needs to connect to an SQL database to send some data from time to time. How can I safely store the username and password used for this job?

like image 974
Alexandru Pupsa Avatar asked Jul 27 '12 09:07

Alexandru Pupsa


1 Answers

Use integrated Windows authentication whenever possible. It takes the onus off of your application and lets Windows handle it. Using Windows authentication instead of SQL authentication is considered a best practice.

Read this accepted answer: the best way to connect sql server (Windows authentication vs SQL Server authentication) for asp.net app

See also: http://www.mssqltips.com/sqlservertip/1831/using-windows-groups-for-sql-server-logins-as-a-best-practice/

And: http://www.greensql.com/content/sql-server-security-best-practices

Incidentally, if this is a "job" as implied by the question, it may be a great candidate for a simple Windows service or scheduled task, both of which can run in a specific security context (i.e. as a specific Windows user).

like image 103
Tim M. Avatar answered Oct 05 '22 09:10

Tim M.