How to hide password from app.config file?

Asked

Viewed 409 times

0

Whenever I go to create a new stringconnection, Visualstudio asks me if I want to leave the visible password in the app.config file

I always say yes, because I don’t know how to insert it directly via code.

How can I delete this password from the file and make the connection at runtime avoiding as soon as someone opens the app.config file and see the password there?

I’m using Visual Studio 2015, Entity Framework 6 and Mysql

  • 1

    Since you have not put any code context you use, make sure that this example of creating Dbcontext helps you by passing the connection object: https://msdn.microsoft.com/en-us/library/dn456849(v=vs.113). aspx

  • You can encrypt the Connection string using Aspnet_regiis.exe

  • 1

    If encrypting the Connectionstring is sufficient for you, then I believe it is a duplicate of https://answall.com/a/143014/46243. If that is not the case, you will need to provide more details on this question of yours. When a connection to the bank is requested, a screen asking for the password (once only) is sufficient?

1 answer

3

You can encrypt the Connection string using the utility aspnet_regiis which is located in %systemroot% Microsoft.NET Framework\

In case to encrypt the section connectio strings the command would be aspnet_regiis -pe "connectionStrings" -app "/Sampleapplication" where "Sampleapplication" is the name of your application.

So the Framework itself will read the string Connection.

More information here and example of Codeproject

  • I’m using the command: ASPNET_REGIIS -pef "connectionStringas" "C:\Program Files (x86)\WiConsultoria\Controle de Estoque\" and I get the error: Criptografando a seção de configuração...
Caracteres inválidos no caminho.
Falha! what can be?

  • Now I realized I used the link code you posted and not your post. I’m going to test now

  • Using your code like this: ASPNET_REGIIS -pe "connectionStrings" -app "/EstoqueFarmacia" received the following error: Criptografando a seção de configuração...
Um arquivo de configuração não pode ser criado para o objeto Configuration solicitado.
Falha!

  • Run a test: changes -pe to -Pef and indicates the folder where web is.config. Just to confirm that the error is the same

  • Doing so: ASPNET_REGIIS -pe "connectionStrings" -app "/EstoqueFarmacia" all available parameters are listed, as if it were a help

  • I used so: ASPNET_REGIIS -pef "connectionStringas" "C:\Progra~1\WiCons~1\Contro~1\" and so: ASPNET_REGIIS -pef "connectionStringas" "C:\Program Files (x86)\WiConsultoria\Controle de Estoque\" Made an error of Caracteres inválidos no caminho

  • Is the command prompt being opened with administrator permissions? It would be the case that the web section name.config is being passed with "connectionStringas" instead of "connectionStrings"?

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.