zoukankan      html  css  js  c++  java
  • Sql注入防小试

    using System;

    namespace Common
    {
     /// <summary>
     /// CheckParameter 的摘要说明。
     /// </summary>
     public class CheckParameter
     {
      public CheckParameter()
      {
       //
       // TODO: 在此处添加构造函数逻辑
       //
      }
      public static String[] chk = {
               " ",
               "'",
               "=",
               "-",
               "+",
               "\\",
               "/",
               "<",
               ">",
               "*",
               "%",
               "and",
               "exec",
               "insert",
               "select",
               "delete",
               "update",
               "count",
               "chr",
               "mid",
               "master",
               "truncate",
               "char",
               "declare"
              };
     
      /// <summary>
      /// 过滤字符串,是否包含指定的字符
      /// </summary>
      /// <param name="strParameter"></param>
      /// <returns>bool</returns>
      public  static  bool IsDangerChar(string strParameter)
      {
       bool flag = false;
       for(int i = 0;i<chk.Length; i ++)
       {
        if(strParameter.IndexOf(chk[i].ToLower()) >= 0)
        {
        
         flag = true;
         break;
        }
        else
        {
         flag = false;
        }
       }
       return flag;
      }
      /// <summary>
      /// 参数是否只包含数字
      /// </summary>
      /// <param name="strId"></param>
      /// <returns>bool</returns>
      public static bool IsNumber(string strId)
      {
       Char[] pn =strId.ToCharArray();
       bool flag = false;
       for(int i=0;i<pn.Length;i++)
       {
        if(pn[i] == '1')
        {
         flag = true;
        }
        else if( pn[i] == '2')
        {
         flag = true;
        }
        else if( pn[i] == '3')
        {
         flag = true;
        }
        else if( pn[i] == '4')
        {
         flag = true;
        }
        else if( pn[i] == '5')
        {
         flag = true;
        }
        else if( pn[i] == '6')
        {
         flag = true;
        }
        else if( pn[i] == '7')
        {
         flag = true;
        }
        else if( pn[i] == '8')
        {
         flag = true;
        }
        else if( pn[i] == '9')
        {
         flag = true;
        }
        else if( pn[i] == '0')
        {
         flag = true;
        }
        else
        {
         flag = false;
         break;
        }
       }
       return flag;
      }
     
     }
    }

    还要根据数据库中字段数值类型的长度,判断参数的长度,否则会出现数据库异常。

    最后判断ID是否存在,不存在则需要处理。

    人的一生应该这样度过:当他回首往事的时候,不会因为虚度年华而悔恨,也不会因为碌碌无为而羞愧。
  • 相关阅读:
    codeforces round #234B(DIV2) B Inna and New Matrix of Candies
    关于禁止ipad的home键解决方法
    ios cocos2d 画线出现闪烁问题
    ios 关于[xxx timeIntervalSinceNow]出现EXC_BAD_ACCESS错误的解决办法
    Codeforces Round #228 (Div. 2) B. Fox and Cross
    Codeforces Round #228 (Div. 2) A. Fox and Number Game
    c语言 %p
    xcode 编译opencv ios容易出现的错误
    ios编译ASIHTTPRequest时出现 'libxml/HTMLparser.h' file not found in ASIHTTPRequest
    当编译CCBReader时出现 “ CCBAnimationManager.m Use of undeclared identifier 'other‘ ” 解决方法
  • 原文地址:https://www.cnblogs.com/htht66/p/893986.html
Copyright © 2011-2022 走看看