Skip to main content

Practice ยท 1 of 4

Parameterize the Query

CHALLENGE
Difficulty: intermediate+25 XP

LoginQuery(sql) builds a login lookup by pasting the username into the query text โ€” the classic injection. Write Solution.BuildLoginQuery(string username) returning the safe pair (sql, parameterValue): ``csharp public static class Solution { public static (string Sql, string Value) BuildLoginQuery(string username); } ` Contract, graded through the provided CjQuery engine (which mimics a real driver: placeholders mean "data", pasted text means "query"): - the SQL contains a @p0 placeholder โ€” the username never appears in the SQL text, - the username travels as the parameter value, - CjQuery.MatchedUsers(sql, value) returns 1 for a normal username and for the injection attempt "' OR '1'='1"` โ€” the attack must be treated as just a (nonexistent) username, never as "match everything".

Back to lesson: Practice: Security Practice: Barriers at the Boundary