Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 651785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:12:01+00:00 2026-05-13T22:12:01+00:00

I want to cach input, which seems to be like SQL injection. I know

  • 0

I want to cach input, which seems to be like SQL injection. I know now, that Reg-ex usage for finding SQL-injections is not a best way, but i simply need to do some researcha about it and I’m asking for help to fix some errors. So I wrote the method:

public static bool IsInjection(string inputText)
{


    bool isInj = false;


    string regexForTypicalInj = @"/\w*((\%27)|(\'))((\%6F)|o|(\%4F))((\%72)|r|(\%52))/ix";
    Regex reT = new Regex(regexForTypicalInj);
    if (reT.IsMatch(inputText))
        isInj = true;


    string regexForUnion = @"/((\%27)|(\'))union/ix";
    Regex reUn = new Regex(regexForUnion);
    if (reUn.IsMatch(inputText))
        isInj = true;



    string regexForSelect = @"/((\%27)|(\'))select/ix";
    Regex reS = new Regex(regexForSelect);
    if (reS.IsMatch(inputText))
        isInj = true;

    string regexForInsert = @"/((\%27)|(\'))insert/ix";
    Regex reI = new Regex(regexForInsert);
    if (reI.IsMatch(inputText))
        isInj = true;

    string regexForUpdate = @"/((\%27)|(\'))update/ix";
    Regex reU = new Regex(regexForUpdate);
    if (reU.IsMatch(inputText))
        isInj = true;

    string regexForDelete = @"/((\%27)|(\'))delete/ix";
    Regex reDel = new Regex(regexForDelete);
    if (reDel.IsMatch(inputText))
        isInj = true;

    string regexForDrop = @"/((\%27)|(\'))drop/ix";
    Regex reDr = new Regex(regexForDrop);
    if (reDr.IsMatch(inputText))
        isInj = true;

    string regexForAlter = @"/((\%27)|(\'))alter/ix";
    Regex reA = new Regex(regexForAlter);
    if (reA.IsMatch(inputText))
        isInj = true;

    string regexForCreate = @"/((\%27)|(\'))create/ix";
    Regex reC = new Regex(regexForCreate);
    if (reC.IsMatch(inputText))
        isInj = true;

    return isInj;

}

“inputText” – here comes tring type text from some textBoxes.
But seems I have done some mistakes, becouse my code do not detects simple sql- injections. What i do wrong? I guess theres something wrong in defining Regex expressions or something with comparing two values.
Please help me just to fix some of these Reg-ex’es to get work.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:12:02+00:00Added an answer on May 13, 2026 at 10:12 pm

    I am not sure what you were trying to match that wasn’t working but here are a few suggestions for your queries.

    Your first expression,

    string regexForTypicalInj = @"/\w*((\%27)|(\'))((\%6F)|o|(\%4F))((\%72)|r|(\%52))/ix";
    

    seems to be intended to catch a single quote followed by “or”. I would make sure to handle the case when there is space after the single quote and before the “or”. Also, you shouldn’t need to escape the % or ‘ characters. With those changes it becomes,

    string regexForTypicalInj = @"/\w*((%27)|')\s*(o|(%6F)|(%4F))(r|(%72)|(%52))/ix";
    

    The rest of the expressions, I would add the space allowance and also include the url-encoded characters as well. Doing that they become,

    string regexForUnion = @"/((%27)|')\s*(u|%75|%55)(n|%6E|%4E)(i|%69|%49)(o|%6F|%4F)(n|%6E|%4E)/ix";
    string regexForSelect = @"/((%27)|')\s*(s|%73|%53)(e|%65|%45)(l|%6C|%4C)(e|%65|%45)(c|%63|%43)(t|%74|%54)/ix";
    string regexForInsert = @"/((%27)|')\s*(i|%69|%49)(n|%6E|%4E)(s|%73|%53)(e|%65|%45)(r|%72|%52)(t|%74|%54)/ix";
    string regexForUpdate = @"/((%27)|')\s*(u|%75|%55)(p|%70|%50)(d|%64|%44)(a|%61|%41)(t|%74|%54)(e|%65|%45)/ix";
    string regexForDelete = @"/((%27)|')\s*(d|%64|%44)(e|%65|%45)(l|%6C|%4C)(e|%65|%45)(t|%74|%54)(e|%65|%45)/ix";
    string regexForDrop = @"/((%27)|')\s*(d|%64|%44)(r|%72|%52)(o|%6F|%4F)(p|%70|%50)/ix";
    string regexForAlter = @"/((%27)|')\s*(a|%61|%41)(l|%6C|%4C)(t|%74|%54)(e|%65|%45)(r|%72|%52)/ix";
    string regexForCreate = @"/((%27)|')\s*(c|%63|%43)(r|%72|%52)(e|%65|%45)(a|%61|%41)(t|%74|%54)(e|%65|%45)/ix";
    

    One other suggestion for the code in general: For each if statement I would suggest replacing isInj = true; with return true; so that you don’t waste time doing unnecessary comparisons. In reality it probably won’t make any performance difference but it could if you were calling that function really often.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 316k
  • Answers 316k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer just use the shell, for file in myfile* do t=${file#*_}… May 13, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer You need to specify an absolute URL for the REFRESH… May 13, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer At first glance looks like the problem you're having is… May 13, 2026 at 11:31 pm

Related Questions

I want to loop over the contents of a text file and do a
I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal
I want to create a Java application bundle for Mac without using Mac. According
I want to create a client side mail creator web page. I know the
I want to reference a COM DLL in a .NET project, but I also

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.