zoukankan      html  css  js  c++  java
  • C# 特殊字符过滤拦截

     public static string ReplaceSQLChar(string str)
            {
                if (str == String.Empty)
                    return String.Empty;
                str = str.Replace("'", "");
                str = str.Replace(";", "");
                str = str.Replace(",", "");
                str = str.Replace("?", "");
                str = str.Replace("<", "");
                str = str.Replace(">", "");
                str = str.Replace("(", "");
                str = str.Replace(")", "");
                str = str.Replace("=", "");
                str = str.Replace("+", "");
                str = str.Replace("*", "");
                str = str.Replace("&", "");
                str = str.Replace("#", "");
                str = str.Replace("%", "");
                str = str.Replace("$", "");
                //删除与数据库相关的词
                str = Regex.Replace(str, "select", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "insert", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "delete from", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "count", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "drop table", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "truncate", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "asc", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "mid", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "char", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "xp_cmdshell", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "exec master", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "net localgroup administrators", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "and", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "net user", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "or", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "net", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "delete", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "drop", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "script", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "update", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "and", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "chr", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "master", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "truncate", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "declare", "", RegexOptions.IgnoreCase);
                str = Regex.Replace(str, "mid", "", RegexOptions.IgnoreCase);
                return str;
            }
  • 相关阅读:
    作诗(si)[分块]
    【洛谷 P3469】[POI2008]BLO-Blockade(割点)
    【洛谷 P2464】[SDOI2008]郁闷的小J(线段树)
    【BZOJ 3907】网格(Catalan数)
    【洛谷 P4211】[LNOI2014]LCA(树链剖分,差分)
    【洛谷 P2480】 [SDOI2010]古代猪文(中国剩余定理,Lucas定理)
    【洛谷 P3842】[TJOI2007]线段(DP)
    【洛谷 P2346】四子连棋(状态压缩,搜索)
    【洛谷 P1363】幻想迷宫(搜索)
    【洛谷 P1364】医院设置(树的重心)
  • 原文地址:https://www.cnblogs.com/BlackAgg/p/13255453.html
Copyright © 2011-2022 走看看