Dict.CN 在线词典, 英语学习, 在线翻译

都市淘沙者

荔枝FM Everyone can be host

统计

留言簿(23)

积分与排名

优秀学习网站

友情连接

阅读排行榜

评论排行榜

通用防SQL注入函数java版

通用防SQL注入函数java版

 public static boolean sql_inj(String str)
 {
    String inj_str = "'|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare|;|or|-|+|,";
    String inj_stra[] = split(inj_str,"|");
    for (int i=0 ; i < inj_stra.length ; i++ )
    {
        if (str.indexOf(inj_stra[i])>=0)
        {
            return true;
        }
    }
    return false;
 }

 jsp中调用该函数检查是否包函非法字符
 <%
 if(request.getParameter("userID") != null)
    userID = request.getParameter("userID").trim();

  if (StringUtil.sql_inj(userID) || StringUtil.sql_inj(pwd)){
   %>
   <Script Language=javascript>alert('参数中包含非法字符!');history.back(-1);</Script>" ;
   <%
  }else{
  ……
 }%>
 StringUtil 是我的通用防注入函数的包名,该函数参考了ASP通用防SQL注入函数,做了一些修改。

posted on 2006-04-26 21:30 都市淘沙者 阅读(544) 评论(0)  编辑  收藏 所属分类: Java Basic/Lucene/开源资料


只有注册用户登录后才能发表评论。


网站导航: