【数据库】 防止sql注入,过滤敏感关键字

private bool FilterIllegalChar(string sWord) 
{
    var result = false;
    var keyWord = @"select|insert|delete|from|count\(|drop table|update|truncate|asc\(|mid\(|char\(|xp_cmdshell|exec master|netlocalgroup administrators|:|net user|""|or|and";
    string StrRegex = @"[-|;|,|/|\(|\)|\[|\]|}|{|%|\@|*|!|']";
    if (Regex.IsMatch(sWord, keyWord, RegexOptions.IgnoreCase) || Regex.IsMatch(sWord, StrRegex))
        return true;

    return result;
}

 

posted @ 2014-11-21 09:53  のんきネコ  阅读(3622)  评论(0编辑  收藏  举报