Ccverify whether the information entered by the user contains a dangerous string

From , 5 Years ago, written in C#, viewed 152 times.
URL https://pastebin.vip/view/69db61ce
  1. /// <summary>
  2.         /// 检测客户输入的字符串是否有效,并将原始字符串修改为有效字符串或空字符串。
  3.         /// 当检测到客户的输入中有攻击性危险字符串,则返回false,有效返回true。
  4.         /// </summary>
  5.         /// <param name="input">要检测的字符串</param>
  6.         public static bool IsValidInput(ref string input)
  7.         {
  8.             try
  9.             {
  10.                 if (IsNullOrEmpty(input))
  11.                 {
  12.                     //如果是空值,则跳出
  13.                     return true;
  14.                 }
  15.                 else
  16.                 {
  17.                     //替换单引号
  18.                     input = input.Replace("'", "''").Trim();
  19.  
  20.                     //检测攻击性危险字符串
  21.                     string testString = "and |or |exec |insert |select |delete |update |count |chr |mid |master |truncate |char |declare ";
  22.                     string[] testArray = testString.Split('|');
  23.                     foreach (string testStr in testArray)
  24.                     {
  25.                         if (input.ToLower().IndexOf(testStr) != -1)
  26.                         {
  27.                             //检测到攻击字符串,清空传入的值
  28.                             input = "";
  29.                             return false;
  30.                         }
  31.                     }
  32.  
  33.                     //未检测到攻击字符串
  34.                     return true;
  35.                 }
  36.             }
  37.             catch (Exception ex)
  38.             {
  39.                 throw new Exception(ex.Message);
  40.             }
  41.         }
  42. //csharp/8601

Reply to "Ccverify whether the information entered by the user contains a dangerous string"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website