Skip to content

Instantly share code, notes, and snippets.

@jearl4
Last active May 25, 2019 04:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Using prepared statements to protect against SQLI
String username = request.getParameter("username");
String password = request.getParameter("password");
String sqlAuthQuery = "select * from users where username = ? and password = ? ";
Connection connection = pool.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sqlAuthQuery);
preparedStatement.setString(1, username);
preparedStatement.setString(2, password);
ResultSet result = preparedStatement.executeQuery();
if (result.next()) {
loggedIn = true;
// Successfully logged in
} else {
// Auth failure
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment