liveBook · Manning

Validation

As explained in 100 SQL Server Mistakes and How to Avoid Them

Input validation is the process of checking supplied data against allowed formats, values, or constraints before processing it.

Mistake: trusting login fields because ordinary tests pass. Without input validation, user-supplied values can alter dynamically built SQL instead of remaining data. section 14.7

A login that accepts more than credentials

A normal login produces a query matching Pete and Password1. A username such as ' OR 1=1-- can turn the predicate true and comment out the password check. The safer practice is to pass login values as stored-procedure parameters rather than concatenate them into SQL. section 14.7

Listing 14.20 Simulating the use of a login stored procedure
DECLARE @UserName NVARCHAR(128) = 'Pete' ;
DECLARE @Password NVARCHAR(128) = 'Password1' ;
 
EXEC dbo.Login @username, @password ;              #1
 
 
SET @UserName = ''' OR 1=1--' ;
SET @Password = 'randomchars' ;
 
EXEC dbo.Login @username, @password ;              #2

Compare an ordinary login with an injected value while tracing how parameterized procedure calls receive the same inputs. section 14.7

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Demonstrates the vulnerability and injection result, then stops short of defining a validation checklist or validation rules.
Examples
Uses a C# Web Forms login, a Users table, a normal credential query, and the payload ' OR 1=1--.
What it assumes
Assumes basic SQL and web-login familiarity while demonstrating the insecure pattern explicitly.
What you can do after
Apply it by replacing concatenated login input with stored-procedure parameters and testing an injection payload.
How it connects
Connects input validation with SQL injection, dynamic SQL, authentication, and stored procedures.

Also explained in

Compare how 30 books explain validation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.