Google turns up all sorts of discussions on sanitizing queries for web access but I\'m not finding anything addressing what I\'m concerned with:
Sanitizing user inpu
Use a properly constructed DAL with SQL Parameter objects handed to stored procedures and you don't have to worry about this. Implement business objects and dal to abstract the user input enough that it isn't executed as SQL but rather recognized as values. examples are fun:
public class SomeDal
{
public void CreateUser(User userToBeCreated)
{
using(connection bla bla)
{
// create and execute a command object filling its parameters with data from the User object
}
}
}
public class User
{
public string Name { get; set; }
...
}
public class UserBL
{
public CreateUser(User userToBeCreated)
{
SomeDal myDal = new SomeDal();
myDal.CreateUser(userToBeCreated);
}
}
public class SomeUI
{
public void HandleCreateClick(object sender, e ButtonClickEventArgs)
{
User userToBeCreated = new User() { Name = txtName.Text };
UserBL userBl = new UserBL();
userBl.CreateUser(userToBeCreated);
}
}