Skip to content

Commit 29788eb

Browse files
authored
Remove examples that show insecure practices (#10435)
1 parent ca370f1 commit 29788eb

File tree

45 files changed

+834
-1737
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+834
-1737
lines changed

includes/forms-auth-warning.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> [!WARNING]
2+
> Storing user credentials in the `credentials` section is **insecure**. Instead, use [Azure Key Vault](/azure/key-vault/general/overview).

includes/ropc-warning.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> [!WARNING]
2+
> Microsoft does not recommend providing your user name and password directly, because it's an insecure pattern. Where possible, use more secure authentication flows, such as [Managed Identities for Azure resources](/sql/connect/ado-net/sql/azure-active-directory-authentication#using-managed-identity-authentication), or [Windows authentication](/sql/relational-databases/security/choose-an-authentication-mode#connecting-through-windows-authentication) for SQL Server.

snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommand.ExecuteReader Example/CS/Project.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
7-
7+
88
<ItemGroup>
9-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1010
</ItemGroup>
11-
11+
1212
</Project>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
2+
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
7-
7+
88
<ItemGroup>
9-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1010
</ItemGroup>
11-
11+
1212
</Project>

snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlConnection.BeginTransaction Example/CS/Project.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1010
</ItemGroup>
1111

12-
</Project>
12+
</Project>

snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlConnection.BeginTransaction2 Example/CS/Project.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1010
</ItemGroup>
1111

12-
</Project>
12+
</Project>

snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlConnection.BeginTransaction3 Example/CS/Project.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1010
</ItemGroup>
1111

12-
</Project>
12+
</Project>

snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlDataReader.Read Example/CS/SqlDataReader.Read.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
6-
<Nullable>enable</Nullable>
5+
<TargetFramework>net8.0</TargetFramework>
76
</PropertyGroup>
87

98
<ItemGroup>
10-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1110
</ItemGroup>
1211

1312
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
10+
</ItemGroup>
11+
12+
</Project>

snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlConnectionStringBuilder.Remove/CS/source.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,29 @@ static void Main()
1010
try
1111
{
1212
string connectString =
13-
"Data Source=(local);User ID=ab;Password= a1Pass@@11;" +
13+
"Data Source=(local);User ID=ab;Password=myPassw0rd;" +
1414
"Initial Catalog=AdventureWorks";
1515

16-
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString);
17-
Console.WriteLine("Original: " + builder.ConnectionString);
16+
SqlConnectionStringBuilder builder = new(connectString);
17+
Console.WriteLine($"Original: {builder.ConnectionString}");
1818

19-
// Use the Remove method
20-
// in order to reset the user ID and password back to their
21-
// default (empty string) values.
19+
// Remove the User ID and Password.
2220
builder.Remove("User ID");
2321
builder.Remove("Password");
2422

25-
// Turn on integrated security:
23+
// Enable integrated security.
2624
builder.IntegratedSecurity = true;
2725

28-
Console.WriteLine("Modified: " + builder.ConnectionString);
29-
30-
using (SqlConnection
31-
connection = new SqlConnection(builder.ConnectionString))
32-
{
33-
connection.Open();
34-
// Now use the open connection.
35-
Console.WriteLine("Database = " + connection.Database);
36-
}
26+
Console.WriteLine($"Modified: {builder.ConnectionString}");
3727
}
3828
catch (Exception ex)
3929
{
4030
Console.WriteLine(ex.Message);
4131
}
42-
43-
Console.WriteLine("Press any key to finish.");
44-
Console.ReadLine();
4532
}
4633
}
34+
/* This code example produces the following output:
35+
* Original: Data Source=(local);Initial Catalog=AdventureWorks;User ID=ab;Password=myPassw0rd
36+
* Modified: Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True
37+
*/
4738
// </Snippet1>

0 commit comments

Comments
 (0)