sql注入过滤

来源:互联网 发布:佛山市发发鱼网站源码 编辑:程序博客网 时间:2024/05/06 04:51

       /// <summary>
        ///SQL注入过滤
        /// </summary>
        /// <param name="InText">要过滤的字符串</param>
        /// <returns>如果参数存在不安全字符,则返回true</returns>
        public static bool SqlFilter(string InText)
        {
            string word = "and|20%and20%|insert|select|delete|update|chr|mid| master |20%master20%|or|truncate|char|declare|join";
            //string word = "and|exec|insert|select|delete|update|chr|mid|master|or|truncate|char|declare|join";
            if (InText == null)
                return false;
            foreach (string i in word.Split('|'))
            {
                if ((InText.ToLower().IndexOf(i + " ") > -1) || (InText.ToLower().IndexOf(" " + i) > -1))
                {
                    return true;
                }
            }
            return false;
        }