在用户名或者密码框中输入“11‘ or ’1‘ = '1”时,生成的sql语句将为“selec * from userInfo where name = '11' or '1' = '1' and pwd = '11' or '1' = '1'”;该语句永远为真。为了防止sql语句的注入,提高程序的安全性。需要替换危险字符。

Java代码段:

public class Checkstr {
public String dostring(String str){
     str=str.replaceAll(";","");
    str=str.replaceAll("&","&");
     str=str.replaceAll("<","&lt;");
     str=str.replaceAll(">","&gt;");
     str=str.replaceAll("'","");
     str=str.replaceAll("--","");
     str=str.replaceAll("/","");
     str=str.replaceAll("%","");
   return str;
}
}

相关文章:

  • 2021-12-04
  • 2021-07-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2022-01-18
  • 2021-10-14
  • 2021-09-22
相关资源
相似解决方案