Skip to content

Commit

Permalink
Update WeatherForecast.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
KingBain authored Dec 13, 2024
1 parent 954cc1f commit d057662
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,25 @@ public class WeatherForecast
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string? Summary { get; set; }
}

// Test for SQL injection vulnerability
public void GetUserData(string userInput)
{
string connectionString = "Data Source=.;Initial Catalog=TestDB;Integrated Security=True";
using (var connection = new SqlConnection(connectionString))
{
// Vulnerable SQL query
string query = "SELECT * FROM Users WHERE Username = '" + userInput + "'";
var command = new SqlCommand(query, connection);

connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader["Username"]);
}
}
}
}
}

0 comments on commit d057662

Please sign in to comment.