Last active
May 25, 2019 04:01
-
-
Save jearl4/f89b520ec410781cfc0747d261b72d60 to your computer and use it in GitHub Desktop.
Using prepared statements to protect against SQLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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