Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I secure passwords stored inside web.config?

I have added the following settings inside my web.config file to initiate an API call to external system. So I am storing the API URL + username + password as follows:-

<appSettings>     <add key="ApiURL" value="https://...../servlets/AssetServlet" />     <add key="ApiUserName" value="tmsservice" />     <add key="ApiPassword" value="test2test2" />  

Then inside my action method I will be referencing these values when building the web client as follows:-

public ActionResult Create(RackJoin rj, FormCollection formValues)         {            XmlDocument doc = new XmlDocument();            using (var client = new WebClient())                 {                     var query = HttpUtility.ParseQueryString(string.Empty);                     foreach (string key in formValues)                     {                         query[key] = this.Request.Form[key];                     }                      query["username"] = System.Web.Configuration.WebConfigurationManager.AppSettings["ApiUserName"];                     query["password"] = System.Web.Configuration.WebConfigurationManager.AppSettings["ApiPassword"];                      string apiurl = System.Web.Configuration.WebConfigurationManager.AppSettings["ApiURL"]; 

But in this was I will be exposing the username and password and these can be captured by users, so my question is how I can secure the API username and password?

like image 241
john Gu Avatar asked Jan 03 '14 16:01

john Gu


People also ask

Is it safe to store passwords in config file?

Storing a password in the registry does not secure it. Anyone with access to the server can read it there.

How do I encrypt an entire web config file?

Encrypting a Web Configuration Section To encrypt configuration file contents, use the Aspnet_regiis.exe tool with the –pe option and the name of the configuration element to be encrypted. Use the –app option to identify the application for which the Web.

Can Web config be hacked?

1) There is always a chance that somehow a hacker manages to read your web. config in one way or another. If a hacker manages to compromise your web server, having your web. config encrypted would at least slow down, if not stop a hacker from gaining access to your database.


1 Answers

You can encrypt the web.config with aspnet_regiis. This is to stop people with access to your server from reading sensitive information.

By the way, I would put your config settings inside a class, that can then be injected into your controllers - it will make unit testing easier.

like image 157
Joe Ratzer Avatar answered Sep 20 '22 05:09

Joe Ratzer