• 防止SQL注入


     1   /// <summary>
     2    /// 过滤SQL注入
     3    /// </summary>
     4    /// <param name="strSQL"></param>
     5    /// <returns></returns>

     6    public static bool CheckSQLInjection(string strSQL)
     7    {
     8        if (string.IsNullOrEmpty(strSQL))
     9        {
    10            return true;
    11        }

    12        else
    13        {
    14            Regex RegExpression = new Regex(@"\s");
    15            strSQL = RegExpression.Replace(strSQL.Trim().Trim().ToLower().Replace("%20"" "), " ");
    16            string Pattern = @"select |insert |delete from |count\(|drop table|update |truncate |asc\(|mid\(|char\(|xp_cmdshell|exec master|net localgroup administrators|:|net user|""|\'| or ";
    17
    18            if (Regex.IsMatch(strSQL, Pattern))
    19            {
    20                return false;
    21            }

    22            else
    23            {
    24                return true;
    25            }

    26        }

    27    }
  • 相关阅读:
    vector数组的翻转与排序
    20210310日报
    vector数组的遍历
    vector数组的删除
    vector数组的插入
    20210304日报
    20210303日报
    20210302日报
    计算datetime.date n个月后(前)的日期
    pandas 重命名MultiIndex列
  • 原文地址:https://www.cnblogs.com/zijinguang/p/1120820.html
Copyright © 2020-2023  润新知