Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - protect against sql injection
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

protect against sql injection

 Post Reply Post Reply
Author
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Topic: protect against sql injection
    Posted: 14 March 2003 at 9:11am
Having read a number of articles about SQL injection attacks, I've seen various advice about replacing the "'" (single quote) character in arguments (simple) and also a recomendation that arguments should only be numeric (most of mine are already, and thanks to MorningZ for the function that guarantees a numeric return); failing that arguments should only contain alphanumeric characters.

A couple of arguments I currently have (and would like to keep) in alphabetic characters, plus the underscore in some cases, eg, "venue" or "venue_name"

In this case, I want to ensure that only letters and the underscore can be returned from the query string; can anyone point me at a function that can do this?

Thanks
www.pedalcars.info

The most fun on four wheels

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2003 at 10:12am

You can use Regular Expressions. The following should do what you are looking for. Only Allows alpha and underscore. The functions returns true or false.

Function ValidateMe(Expression)
   Dim objRegExp
   Set objRegExp = New RegExp
   objRegExp.Pattern = "^[a-zA-Z\_]+$"
   ValidateEmail = objRegExp.Test(Expression)
End Function

Use like
If ValidateMe(strWhatever) = False Then
 'Raise your error
ELSE
 Continue
END IF

Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2003 at 10:38am
Brilliant, thanks, I'll give it a go.
www.pedalcars.info

The most fun on four wheels

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2003 at 10:54am
I use something a little more flexible

and btw, thats not a SQL Injection issue since they aren't going to hose the SQL query, but sounds just like you just want to validate some data

Here's another common function that i wrote/use for a situation like you are looking for, the "i_xtra" parameter allows you to let any non-alpha character flow through as well

Function CheckAlpha( i_string, i_xtra )
     Dim temp, strAllow
     temp = True
     strAllow = "abcdefghijklmnopqrstuvwxyz"
     if i_xtra <> "" then strAllow = strAllow & i_xtra
     For i = 1 to Len( i_string )
          If InStr( strAllow, Lcase( Mid( i_string, i, 1 ) ) ) = 0 then
               temp = False
               exit for
          end if
     Next
     CheckAlpha = temp
end function


CheckAlpha( "jimbobjoe", "" ) returns true
CheckAlpha( "jim bob joe", "" ) returns false
CheckAlpha( "jim bob joe", " " ) returns true
CheckAlpha( "jim_bob joe", " " ) returns false
CheckAlpha( "jim_bob joe", " _" ) returns true

Contribute to the working anarchy we fondly call the Internet
Back to Top
meteor View Drop Down
Groupie
Groupie
Avatar

Joined: 31 August 2003
Location: Iran
Status: Offline
Points: 67
Post Options Post Options   Thanks (0) Thanks(0)   Quote meteor Quote  Post ReplyReply Direct Link To This Post Posted: 05 June 2004 at 8:18am

how about "OR AND = > <" can this letters make SQL injection. what is Complete Function to Checking Some String inputed from users For SQL injection.like Checking For Name and Password?

Like => isInjection(StringInputed) Return False and true?()

Sincerely
--------------------
PowerFull Scripts For NTTacPlus
Back to Top
meteor View Drop Down
Groupie
Groupie
Avatar

Joined: 31 August 2003
Location: Iran
Status: Offline
Points: 67
Post Options Post Options   Thanks (0) Thanks(0)   Quote meteor Quote  Post ReplyReply Direct Link To This Post Posted: 11 June 2004 at 7:04am

i read about SQL injection , is this Function good for testing strings inputed?

Function isSQLinjection(Input)
 if instr(1,input,"'",1) or instr(1,input,";",1) or instr(1,input,"--",1) then
  isSQLinjection = True
 else
  isSQLinjection = False
 end if
end function

Sincerely
--------------------
PowerFull Scripts For NTTacPlus
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.