您的位置:首页 > 博客中心 > 数据库 >

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

时间:2022-03-14 02:47

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;
}

 

热门排行

今日推荐

热门手游