0

I have some Regex, it looks like this:

string regexForDrop = @"^((%27)|'|(\-\-))\s*(d|%64|%44)(r|%72|%52)(o|%6F|%4F)(p|%70|%50)$";

It works fine, when i write to the input "--drop", but it does not works, when i write "drop table users" or something like that. I need that it would be working, no matter what comes after "--drop". How i can implement that?

Thanks

6
  • 2
    Are you trying to prevent SQL injection attacks here? Commented Mar 8, 2010 at 21:18
  • 4
    I would highly advise against using a regex as a method of security for SQL injection. It's a recipe for getting hacked Commented Mar 8, 2010 at 21:21
  • 3
    Even if it works for "--drop", what about "--truncate" or any host of other evil things someone could do. Commented Mar 8, 2010 at 21:23
  • -1 for being one of the most stupid ideas ever. Commented Mar 8, 2010 at 21:29
  • 1
    Yes, I know about SP, I just do some research for studies about regex to. Commented Mar 8, 2010 at 21:30

3 Answers 3

6

It seems you trying to prevent a sql injection attack. For this use Parameterized Queries this way you don't need to check for injections.

Good Read:
http://weblogs.asp.net/scottgu/archive/2006/09/30/Tip_2F00_Trick_3A00_-Guard-Against-SQL-Injection-Attacks.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I know about SP, i just do some research for studies about regex to. Thanks for the link, I would read it.
2
string regexForDrop = @"^((%27)|'|(\-\-))\s*(d|%64|%44)(r|%72|%52)(o|%6F|%4F)(p|%70|%50).*$";

? or without the $

1 Comment

+1, whatever @Vytas999 reason, you wrote the code to solve it
1

Remove the '$' at the end of your regular expression. $ matches the end of the input string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.