MultiLevelLogin2 database

git-svn-id: http://webgoat.googlecode.com/svn/trunk@310 4033779f-a91e-0410-96ef-6bf7bf53c507
This commit is contained in:
wirth.marcel 2008-04-09 12:05:28 +00:00
parent fa0c7eff8a
commit 361e142442

View File

@ -488,10 +488,10 @@ public class MultiLevelLogin2 extends LessonAdapter
private void updateTan(String user, WebSession s) private void updateTan(String user, WebSession s)
{ {
int tanNr = getTanPosition(user, s); int tanNr = getTanPosition(user, s);
Connection connection = null;
try try
{ {
Connection connection = DatabaseUtilities.getConnection(s); connection = DatabaseUtilities.getConnection(s);
String query = "UPDATE user_data_tan SET login_count = ? WHERE first_name = ?"; String query = "UPDATE user_data_tan SET login_count = ? WHERE first_name = ?";
PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY); ResultSet.CONCUR_READ_ONLY);
@ -503,6 +503,20 @@ public class MultiLevelLogin2 extends LessonAdapter
{ {
e.printStackTrace(); e.printStackTrace();
} }
finally
{
try
{
if (connection != null)
{
connection.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
} }
@ -515,9 +529,10 @@ public class MultiLevelLogin2 extends LessonAdapter
*/ */
private ResultSet getUser(String user, WebSession s) private ResultSet getUser(String user, WebSession s)
{ {
Connection connection = null;
try try
{ {
Connection connection = DatabaseUtilities.getConnection(s); connection = DatabaseUtilities.getConnection(s);
String query = "SELECT * FROM user_data_tan WHERE first_name = ? "; String query = "SELECT * FROM user_data_tan WHERE first_name = ? ";
PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY); ResultSet.CONCUR_READ_ONLY);
@ -531,6 +546,20 @@ public class MultiLevelLogin2 extends LessonAdapter
{ {
e.printStackTrace(); e.printStackTrace();
} }
finally
{
try
{
if (connection != null)
{
connection.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
return null; return null;
} }
@ -542,10 +571,10 @@ public class MultiLevelLogin2 extends LessonAdapter
*/ */
private void resetTans(WebSession s) private void resetTans(WebSession s)
{ {
Connection connection = null;
try try
{ {
Connection connection = DatabaseUtilities.getConnection(s); connection = DatabaseUtilities.getConnection(s);
String query = "UPDATE user_data_tan SET login_count = 0 WHERE login_count > 0"; String query = "UPDATE user_data_tan SET login_count = 0 WHERE login_count > 0";
PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY); ResultSet.CONCUR_READ_ONLY);
@ -555,6 +584,20 @@ public class MultiLevelLogin2 extends LessonAdapter
{ {
e.printStackTrace(); e.printStackTrace();
} }
finally
{
try
{
if (connection != null)
{
connection.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
} }
@ -568,9 +611,10 @@ public class MultiLevelLogin2 extends LessonAdapter
private int getTanPosition(String user, WebSession s) private int getTanPosition(String user, WebSession s)
{ {
int tanNr = 0; int tanNr = 0;
Connection connection = null;
try try
{ {
Connection connection = DatabaseUtilities.getConnection(s); connection = DatabaseUtilities.getConnection(s);
String query = "SELECT login_count FROM user_data_tan WHERE first_name = ?"; String query = "SELECT login_count FROM user_data_tan WHERE first_name = ?";
PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY); ResultSet.CONCUR_READ_ONLY);
@ -591,6 +635,20 @@ public class MultiLevelLogin2 extends LessonAdapter
{ {
e.printStackTrace(); e.printStackTrace();
} }
finally
{
try
{
if (connection != null)
{
connection.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
return tanNr; return tanNr;
} }
@ -605,9 +663,10 @@ public class MultiLevelLogin2 extends LessonAdapter
*/ */
private String getTan(String user, int tanPosition, WebSession s) private String getTan(String user, int tanPosition, WebSession s)
{ {
Connection connection = null;
try try
{ {
Connection connection = DatabaseUtilities.getConnection(s); connection = DatabaseUtilities.getConnection(s);
String query = "SELECT tan.tanValue FROM user_data_tan, tan WHERE user_data_tan.first_name = ? " String query = "SELECT tan.tanValue FROM user_data_tan, tan WHERE user_data_tan.first_name = ? "
+ "AND user_data_tan.userid = tan.userid AND tan.tanNr = ?"; + "AND user_data_tan.userid = tan.userid AND tan.tanNr = ?";
PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE,
@ -628,6 +687,20 @@ public class MultiLevelLogin2 extends LessonAdapter
{ {
e.printStackTrace(); e.printStackTrace();
} }
finally
{
try
{
if (connection != null)
{
connection.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
return ""; return "";
} }
@ -655,9 +728,10 @@ public class MultiLevelLogin2 extends LessonAdapter
*/ */
private boolean correctLogin(String userName, String password, WebSession s) private boolean correctLogin(String userName, String password, WebSession s)
{ {
Connection connection = null;
try try
{ {
Connection connection = DatabaseUtilities.getConnection(s); connection = DatabaseUtilities.getConnection(s);
String query = "SELECT * FROM user_data_tan WHERE first_name = ? AND password = ?"; String query = "SELECT * FROM user_data_tan WHERE first_name = ? AND password = ?";
PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, PreparedStatement prepStatement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY); ResultSet.CONCUR_READ_ONLY);
@ -676,6 +750,20 @@ public class MultiLevelLogin2 extends LessonAdapter
{ {
e.printStackTrace(); e.printStackTrace();
} }
finally
{
try
{
if (connection != null)
{
connection.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
return false; return false;