Add*_*ted 2 java sql-injection jdbc
如何防止sql注入我使用下面的代码登录
con = DriverManager.getConnection("", "", "");
Statement statement = con.createStatement();
ResultSet rs= statement.executeQuery("SELECT email,pass FROM db_pass where email='" + email + "'and pass='" + password + "'" );
if (rs.next()) {
String a=rs.getString(1);
String b=rs.getString(2);
rs.close();
Run Code Online (Sandbox Code Playgroud)
它工作正常但是当它放入(nitin'OR'1'='1)时,用户无需输入有效密码即可访问
使用PreparedStatement.您可以在http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html中找到示例
为防止SQL注入,应对所有查询进行参数化,并且永远不应使用字符串连接来创建动态SQL.
| 归档时间: |
|
| 查看次数: |
424 次 |
| 最近记录: |