title: Where to store db passwords when using Windows .NET or ASP.NET applications
body: <p>I have a scenario that has been troubling me for years. If you have to connect to a database or other service (like a web service) using a username and password, where would be the safest place to store this information if you are connecting through a .NET assembly? I understand that you would have to encrypt the password, but then you run into a kind of chicken-egg problem -- fine -- you can encrypt it, but then where do you put the key?</p>
  
  <p>In .NET, you can't hard-code the password because you can decompile .NET code.</p>
  
  <p>I looked at using assembly based rights with Isolated Storage, but MS recommends against storing unencrypted secret items there because privileged users can gain access, so again, we are moving the problem from point A to point B. So, for example, a domain admin with no need to know about the information in a database would be able to get access because of the ability to be an admin on any workstation on the domain.</p>
  
  <p>You can encrypt the App. Config and Web.Config, but I believe privileged users can access the keys. </p>
  
  <p>I think you run into the same problem with DPAPI.</p>
  
  <p>I had considered storing the passwords, encrypted in a remote database, and getting them through OS authentication, but our department prohibits the storage of passwords on database servers. I am pretty sure I am stuck and wanted confirmation.</p>