Package org.h2.samples
Class SQLInjection
java.lang.Object
org.h2.samples.SQLInjection
SQL Injection is a common security vulnerability for applications that use
database. It is one of the most common security vulnerabilities for web
applications today. This sample application shows how SQL injection works,
and how to protect the application from it.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringchangePassword(Connection conn, String userName, String password) Utility method to change a password of a user.static ResultSetgetUser(Connection conn, String userName, String password) Utility method to get a user record given the user name and password.static voidThis method is called when executing this sample application from the command line.
-
Constructor Details
-
SQLInjection
public SQLInjection()
-
-
Method Details
-
main
This method is called when executing this sample application from the command line.- Parameters:
args- the command line parameters- Throws:
Exception- on failure
-
getUser
Utility method to get a user record given the user name and password. This method is secure.- Parameters:
conn- the database connectionuserName- the user namepassword- the password- Returns:
- a result set with the user record if the password matches
- Throws:
Exception- on failure
-
changePassword
public static String changePassword(Connection conn, String userName, String password) throws Exception Utility method to change a password of a user. This method is secure, except that the old password is not checked.- Parameters:
conn- the database connectionuserName- the user namepassword- the password- Returns:
- the new password
- Throws:
Exception- on failure
-