Language: C#, SQL
Framework: ASP.NET Core MVC
Target: Web
My web application connects to the database to retrieve information.
I was first learning to implement a working concept and after that, I would improve the security.
public class DataBaseConnection
{
public SqlConnection connection = new SqlConnection("Secret Connection String goes here.");
}
Storing the connection string this way is unsafe, so I looked for alternatives.
Research:
Securing Connection String in ASP.NET MVC
In this question, it is mentioned that:
- It is a better idea to store the connection string in the configuration file.
- To be safe I could encrypt the connection string.
- You don't have to store the username and password in the connection string if you use a Windows Authentication Token.
So, it would look like this:
"AllowedHosts": "*",
"ConnectionStrings": {
"Default": "Data Source=(localdb)\\MSSQLLocalDB; Initial Catalog=TestDB; Integrated Security=True;"
}
My question differs in the fact that I need to connect to an external database.
My problem:
Integrated Security=True; uses the authentication token of the the user that is currently logged into the computer to log into the database and this only works on a local network with an active directory in a test environment.
So, in production, I will have to use a username and password in the connection string.
My question:
Is there a way to connect to an external database (on another network) without storing the username and password in the connection string? So, in a nutshell. Would it be possible to use an authentication token as an alternative in the connection string?