C# 检查字符串,防SQL注入攻击
来源:互联网 发布:java io流怎么用 编辑:程序博客网 时间:2024/06/02 06:48
C# 检查字符串,防SQL注入攻击
这些天,CSDN上讨论SQL注入攻击似乎是如火如荼啊...我也来参合一下..如下,CheckParams函数,接收参数任意,如参数中有字符串,则对字符串进行检查,如参数中有集合(如Array之类,总之是实现了ICollection的),则对集合中的字符串元素进行检查.大家可根据具体情况来定要过滤的字符,我这个例子里暂定为=号和'号,实际上我个人认为,过滤了这两个,似乎要进行SQL注入就已经比较困难了,当然,我对SQL是菜鸟,欢迎高手指正,谢谢.我的邮箱(MSN):Appledotnet@hotmail.com
bool CheckParams(params object[] args){ string[] Lawlesses={"=","'"}; if(Lawlesses==null||Lawlesses.Length<=0)return true; //构造正则表达式,例:Lawlesses是=号和'号,则正则表达式为 .*[=}'].* (正则表达式相关内容请见MSDN) //另外,由于我是想做通用而且容易修改的函数,所以多了一步由字符数组到正则表达式,实际使用中,直接写正则表达式亦可; string str_Regex=".*["; for(int i=0;i< Lawlesses.Length-1;i++) str_Regex+=Lawlesses[i]+"|"; str_Regex+=Lawlesses[Lawlesses.Length-1]+"].*"; // foreach(object arg in args) { if(arg is string)//如果是字符串,直接检查 { if(Regex.Matches(arg.ToString(),str_Regex).Count>0) return false; } else if(arg is ICollection)//如果是一个集合,则检查集合内元素是否字符串,是字符串,就进行检查 { foreach(object obj in (ICollection)arg) { if(obj is string) { if(Regex.Matches(obj.ToString(),str_Regex).Count>0) return false; } } } } return true;}
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C#检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- 防SQL注入攻击
- JSP防SQL注入攻击
- SQL 防注入式攻击
- 防SQL注入式攻击
- paper 感悟
- TLD的Matlab源码学习
- 天才 法布里斯贝拉(Fabrice Bellard)
- java实现插入排序
- leveldb研究系列五——Ssttable组件
- C# 检查字符串,防SQL注入攻击
- Median of Two Sorted Arrays(OO)
- Android各种屏幕分辨率(VGA、HVGA、QVGA、WQVGA、WVGA、FWVGA) 详解 .
- fopen()函数与fread()函数区别
- 对ASP.NET页面生命周期总结(2)
- google hacking
- [C#] TextBox限制输入长度(中文字算2码)
- jsp乱码处理
- 10个有用的第三方iOS开源库