Posts

Showing posts with the label .net core tips

Stop SQL Injection in .NET

 The Problem: One Input Box Can Expose Your Entire Database SQL Injection is still one of the top threats in .NET applications, especially when developers build SQL queries by string concatenation. Here’s a classic mistake: string query = "SELECT * FROM Users WHERE Email = '" + email + "' AND Password = '" + password + "'"; If an attacker types this into the email field: ' OR 1=1 -- The query turns into: SELECT * FROM Users WHERE Email = '' OR 1=1 --' AND Password = '' Result: The attacker bypasses login or retrieves all users—a full data breach with one input.   ✅ The Solution: Use Parameterized Queries with ADO.NET or Entity Framework The safest and most effective solution in .NET is parameterized queries. They keep SQL logic and data separate, making injection impossible.   🔐 Example with ADO.NET: using (SqlConnection conn = new SqlConnection(connectionString)) {     SqlCommand cmd...