M
Misbah Arefin
User Input Validation in ASP.NET
http://msdn2.microsoft.com/en-us/library/ms972961.aspx
--
--
Misbah Arefin
http://msdn2.microsoft.com/en-us/library/ms972961.aspx
--
--
Misbah Arefin
Misbah Arefin said:Use SQL parameters for data access. You can use these parameters with
stored procedures or dynamically constructed SQL command strings.
Parameter collections such as SqlParameterCollection provide type checking
and length validation. If you use a parameters collection, input is
treated as a literal value, and SQL Server does not treat it as executable
code. An additional benefit of using a parameters collection is that you
can enforce type and length checks. Values outside of the range trigger an
exception. This is a good example of defense in depth.
To constraint the user to specific text/format use the validatoin controls
in ASP.NET e.g. RegularExpressionValidator
Also, in the rare event when the client side validation did not work
(jscript / browser) you must also validate the input in the server side
code
--
Misbah Arefin
Mr. R said:Mark Rae said:Get the point. I guess I have to validate the commands before sending
them to the SQL Server. When I write programs that access databases
with dynamic SQL you always make sure that the data entered is correct.
No you don't! You simply *NEVER EVER* use dynamic SQL built up from form
fields...
You use either parameterised queries or stored procedures...
I got the point and changed to parameterised update. However when using
the followng SQL command.
select * from [aTable] where [username] = @username;
What happens when the username has the value SOMEUSER and that user
exists.....
"SOMEUSER";DROP TABLE [aTable];--=
*) Does the SQLDataSource only send one SQL command to the server? or is
this server dependant. Shurley you would get the same program with Stored
procedures.
*) Does the SQLDataSource component generate SQL commands that are sent
to the database?
*) If so we still have the problemas if I would build Strings and send to
the server.
*) Do I have to add protection so the user can't enter invalid characters
such as ";" and how do you do that in C# and ASP.NET? As far as I see
there's no other way to be sure than to make sure the user can't enter
invalid values to the database. Does C# have any build in functions to
check this. I use the validators to verify password and for making sure
the user enters no empty (null) fields. But feel I need to a validators
so that the use can't enter an invalid parameter. For example a phone
number should only insude numbers and spaces. A string field should be
alpha numeric etc. The demo viedeos haven't discussed this (yet). But the
videos are to slow. Have to watch a video for 30 minutes just for the guy
to show how to add a FormsView. Readding the database connection string,
same select commands again and again. This is trivial to me. Upon that
the guy in the videos uses "absolute positioning", brrr.
Lars