473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Making user input safe

Hi there,

I am working on a project were a user can update a SQL Server DB via a web
form. I've included a number of text boxes for a user to enter in strings.
The text from these boxes is then used in an update command. My problem is
if the user enters any speech marks then it will break the code as they are
interpretted as the end of the SQL statement. I'm sure there are other
characters which will also cause problems.

Here is a code snippet.
sSQL = "INSERT INTO t_links VALUES (" & "'" & tbLinkName.Text() & "'" & ","
& "'" & tbLinkAddress.Text() & "'" & "," & "'" & tbLinkDescription.Text() &
"'" & ")"

Is there any automated way of turning the contents of these text boxes into
their literal form so the contents can be safely used in this way?

In PHP you've got HTMLSpecialChars function which will turn script/html into
the actual text we want. Is there anything like this I can use for VB.net?

Thanks

Steve


Nov 21 '05 #1
4 1395
On Thu, 04 Nov 2004 17:31:51 GMT, "Stephen Adam"
<st**********@ntlworld.com> wrote:
Hi there,

I am working on a project were a user can update a SQL Server DB via a web
form. I've included a number of text boxes for a user to enter in strings.
The text from these boxes is then used in an update command. My problem is
if the user enters any speech marks then it will break the code as they are
interpretted as the end of the SQL statement. I'm sure there are other
characters which will also cause problems.

Here is a code snippet.
sSQL = "INSERT INTO t_links VALUES (" & "'" & tbLinkName.Text() & "'" & ","
& "'" & tbLinkAddress.Text() & "'" & "," & "'" & tbLinkDescription.Text() &
"'" & ")"

Is there any automated way of turning the contents of these text boxes into
their literal form so the contents can be safely used in this way?

In PHP you've got HTMLSpecialChars function which will turn script/html into
the actual text we want. Is there anything like this I can use for VB.net?

Thanks

Steve

You want to change single quotes into two single quotes..

Instead of using:

tbLinkName.Text()

Try using:

tbLinkName.Text().Replace("'","''")
Same for any other text data that may contain single quotes..

// CHRIS

Nov 21 '05 #2
Hi Steve,

The first thing I would recommend is using Stored Procedures. This is
faster and safer and you don't have to worry about things like apostrophes
and quotes. The way you are doing it now a user could go to your site and
perform a SQL injection to knock out your database or worse steal all your
information. To help protect against this doing it your way, make sure you
limit the number of characters that can be typed into each textbox. For
your solution I suggest writing a routine that takes a string and makes it
SQL compatible. Something that adds an apostrophe if there is only one and
etc. Then when you create your SQL statement use this routine for each text
box:

"Insert Into......" + SafeSQL(tbLinkName.Text) + "....."

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Stephen Adam" <st**********@ntlworld.com> wrote in message
news:bI*************@newsfe6-win.ntli.net...
Hi there,

I am working on a project were a user can update a SQL Server DB via a web
form. I've included a number of text boxes for a user to enter in strings.
The text from these boxes is then used in an update command. My problem is
if the user enters any speech marks then it will break the code as they are interpretted as the end of the SQL statement. I'm sure there are other
characters which will also cause problems.

Here is a code snippet.
sSQL = "INSERT INTO t_links VALUES (" & "'" & tbLinkName.Text() & "'" & "," & "'" & tbLinkAddress.Text() & "'" & "," & "'" & tbLinkDescription.Text() & "'" & ")"

Is there any automated way of turning the contents of these text boxes into their literal form so the contents can be safely used in this way?

In PHP you've got HTMLSpecialChars function which will turn script/html into the actual text we want. Is there anything like this I can use for VB.net?

Thanks

Steve

Nov 21 '05 #3
"Stephen Adam" <st**********@ntlworld.com> schrieb:
Here is a code snippet.
sSQL = "INSERT INTO t_links VALUES (" & "'" & tbLinkName.Text() & "'" & "," & "'" & tbLinkAddress.Text() & "'" & "," & "'" & tbLinkDescription.Text() & "'" & ")"


Use an '*InsertCommand' + parameters instead:

Using Parameters with a 'DataAdapter'
<URL:http://msdn.microsoft.com/library/en...nusingparamete
rswithdataadapters.asp>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #4
Thanks for the advice guys :)

Got the double quotes sorted now and will look into using stored procedures,
SQL injection looks pretty nasty!

Cheers

Steve
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: |-|erc | last post by:
Hi! Small challenge for you. The index.php uses this file and calls layout(). Take a look at www.chatty.net this file draws the chat login box on the right. I traced the CHAT button it submits...
2
by: nntp-service.ohio-state.edu | last post by:
Hey folks - I'm a newbie to java script. I'm trying to make a portable data-validator for fields in an HTML form. Ideally, it would work something like this: <input type="text" name="test"...
23
by: ern | last post by:
I have a program that runs scripts. If the user types "script myScript.dat" the program will grab commands from the text file, verify correctness, and begin executing the script UNTIL... I need...
8
by: Radith | last post by:
Hi All, I have a number guessing game in which users try to guess a random number. Obviously, input is required of type int. BUT, when a user inputs a string the program will result in an...
22
by: tricard | last post by:
Good evening, I was thinking about making a very simple DOS based (console) menu for a project that i am working on, but I have no idea where to start for something like this. Does anyone have...
4
by: FlaPnthrsPunk | last post by:
Hi all, this is my first time ever using PHP, and I am still very new to programming in general. I'm doing an assignment for my Media E-Commerce class where the code for a survey is all provided. ...
2
by: tavspamnofwd | last post by:
Referred here from the tutor list. ---------- Forwarded message ---------- From: Evert Rol Hi Tom, Ok, I wasn't on the list last year, but I was a few days ago, so persistence pays off;...
2
by: Philipp Lenssen | last post by:
The question in short: how do I make eval() safe? The background: At questml.com I'm offering a way to create choose- your-own-adventures in a special XML dialect. There's a several-years- old...
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.