.NET防止用户恶意输入
来源:互联网 发布:决战平安京邀请码淘宝 编辑:程序博客网 时间:2024/04/30 09:06
/// <summary>
/// 该方法用来检测用户输入是否带有恶意
/// </summary>
/// <param name="text">用户输入的文字</param>
/// <param name="maxlength">最大的长度</param>
/// <returns>返回验证后的文字</returns>
public static string InputText(string text, int maxlength)
{
text = text.ToLower().Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
if (text.Length > maxlength)
text = text.Substring(0, maxlength);
text = Regex.Replace(text, "[\\s]{2,{", " ");
text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n"); //<br>
text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " "); //
text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); //any other tags
text = Regex.Replace(text,"=", "");
text = Regex.Replace(text, "%", "");
text = Regex.Replace(text, "'", "");
text = Regex.Replace(text, "select", "");
text = Regex.Replace(text, "insert", "");
text = Regex.Replace(text, "delete", "");
text = Regex.Replace(text, "or", "");
text = Regex.Replace(text, "exec", "");
text = Regex.Replace(text, "--", "");
text = Regex.Replace(text, "and", "");
text = Regex.Replace(text, "where", "");
text = Regex.Replace(text, "update", "");
text = Regex.Replace(text, "script", "");
text = Regex.Replace(text, "iframe", "");
text = Regex.Replace(text, "master", "");
text = Regex.Replace(text, "exec", "");
text = Regex.Replace(text, "<", "");
text = Regex.Replace(text, ">", "");
text = Regex.Replace(text, "\r\n", "");
return text;
}
来源于:www.hackbadboy.com B.B.S.T 信息安全团队 BadBoy网络安全小组
- .NET防止用户恶意输入
- 防止恶意字符输入
- 防止用户恶意刷新过滤器
- 防止用户恶意刷新过滤器
- iOS防止用户恶意点击场景分析、防止用户恶意点击方法之本地动态验证码生成
- 怎么防止用户输入错误信息
- .net防止同一用户登陆
- AcceptEx防止恶意攻击
- php 防止恶意刷新
- 防止恶意登录机制
- 防止恶意点击
- apache防止恶意解析
- 防止用户在地址栏非法输入
- 防止浏览器默认记录用户输入值
- web 应用 防止用户输入中文乱码
- 防止用户提交的表单内容里可能会写入一些恶意的代码
- 新手--Discuz!使用技巧如何防止用户在论坛恶意灌水?
- ASP.NET防止用户跳过登陆界面
- js基础学习第一天(关于DOM和BOM)一
- Fedora 15下搭建PPTP服务
- Python Paste.deploy 笔记
- Android 2.3的StrictMode使用
- 绩效分数改善
- .NET防止用户恶意输入
- Silverlight实例教程 - Validation数据验证DataAnnotation机制和调试技巧 2010
- 如何修改Tomcat服务器的重定向端口(redirectPort)号
- java解压RAR压缩文件
- 参加ios Tech Talk World Tour
- DataAnnotation脱离MVC独立验证
- ThreeJS里支持哪种格式/导出方式
- 转义字符"\"使用和@在C#中用的妙用
- Android控件之ExpandableListView