473,382 Members | 1,409 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,382 software developers and data experts.

Validate form input to protect against SQL Attack

Hi there I am trying to get my action page of the website I'm building to check to see if the form input values are empty, if they are not it will then check to see if any of the form inputs contain any SQL. I have read in some other places that you can use cfparam or cfqueryparam to stop this but I don't really know how to use them.

This is the code:

Expand|Select|Wrap|Line Numbers
  1. <cfif len(form.username) EQ 0 OR len(form.password) EQ 0>
  2.             <p>You did not enter a username or password</p>
  3.             <p><a href="index.cfm">Please go back and try again</a></p>
  4.           <cfelse>
  5.             <cfquery name = "login" datasource="blah">
  6.             SELECT login, password
  7.             FROM member
  8.             WHERE login = '#form.username#' AND password = '#form.password#'
  9.             </cfquery>
  10.  
  11.             <cfif login.RecordCount GT 0>
  12.  
  13.               <cfif '#form.username#' EQ #login.login# AND '#form.password#' EQ #login.password#>
  14.                   <p> Your name is right...</p>
  15.                   <cfset session.memberLogin = #form.username#>
  16.               <cfelse>
  17.                   <p>Sorry incorrect username or password, please try again</p>
  18.                   <cflocation url="index.cfm">
  19.               </cfif>
  20.  
  21.               <cfoutput>
  22.                   <cfif session.name IS "admin">
  23.                       <cflocation url="index.cfm">
  24.                   <cfelse>
  25.                       <cflocation url="profile.cfm?un=#session.name#">
  26.                   </cfif>
  27.               </cfoutput>    
  28.  
  29.             <cfelse>
  30.               <p>Sorry you entered an incorrect username/password</p>
  31.               <p><a href="index.cfm">Try again here!</a></p>
  32.             </cfif>
  33.  
  34.         </cfif>
  35.  
Any help would be awesome, thanks.
Mar 26 '09 #1

✓ answered by jKara

@sc0705837
It is cfqueryparam. It does not check to see if the inputs contain SQL, but rather _helps_ prevent malicious sql from being executed in the query by enforcing data type rules.

Using cfqueryparam is very simple. The most basic form requires only: "value" and "cfsqltype". The cfsqltype is a string value that represents the data type of your table column. The correct values to use are determined by database type, but some examples are: cf_sql_varchar, cf_sql_integer, etc...

You can find more information about cfqueryparam it in the online documentation
http://livedocs.adobe.com/coldfusion...gs_p-q_18.html

Expand|Select|Wrap|Line Numbers
  1. ...
  2. FROM member
  3. WHERE 
  4. login = <cfqueryparam value="#form.username#" cfsqltype="cf_sql_varchar"> AND password = <cfqueryparam value="#form.password#" cfsqltype="cf_sql_varchar"> 
  5.  
  6.  

2 3633
jKara
5
@sc0705837
It is cfqueryparam. It does not check to see if the inputs contain SQL, but rather _helps_ prevent malicious sql from being executed in the query by enforcing data type rules.

Using cfqueryparam is very simple. The most basic form requires only: "value" and "cfsqltype". The cfsqltype is a string value that represents the data type of your table column. The correct values to use are determined by database type, but some examples are: cf_sql_varchar, cf_sql_integer, etc...

You can find more information about cfqueryparam it in the online documentation
http://livedocs.adobe.com/coldfusion...gs_p-q_18.html

Expand|Select|Wrap|Line Numbers
  1. ...
  2. FROM member
  3. WHERE 
  4. login = <cfqueryparam value="#form.username#" cfsqltype="cf_sql_varchar"> AND password = <cfqueryparam value="#form.password#" cfsqltype="cf_sql_varchar"> 
  5.  
  6.  
Mar 27 '09 #2
Right, thanks alot for the help, will just go set this up. Its only a student project so this minimal amount of protection should be good enough.

Thanks again!
Mar 31 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
8
by: Reply Via Newsgroup | last post by:
Folks, I am using Apache 1.3.x with PHP 4.3.x and MySQL v4. Short question: Before I put my web form available on the internet, how can I test it from mis-use in such that special characters...
13
by: teddy.am | last post by:
I know this is stupid, but i've been trying to process a form while adding a function to the onClick event. as soon as i add the onClick event, the function is triggerred but the form doesn't...
10
by: bregent | last post by:
I've seen plenty of articles and utilities for preventing form injections for ASP.NET, but not too much for classic ASP. Are there any good input validation scripts that you use to avoid form...
1
by: Sithlord999 | last post by:
Hello. I'm working on an email form on Dreamweaver and I'm looking for a PHP code to make it work. The form with some required fields would send the submitted information and two image attachments...
1
by: anilareddy | last post by:
I have an application like this. I need to validate the start time in 2nd row against the start row in first row. I mean The start time value entered in the second row must not b the value entered in...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
19
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash...
15
by: learner247 | last post by:
Hi, I am learning csharp and have a question: My question is about handling a receiving socket. I use the backgroundworker class for multithreading. In the doWork event there is a while...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.