Skip to content

Create UserDAO.java#11

Open
vivek-kumar-2024 wants to merge 1 commit intomainfrom
vivek-kumar-2024-patch-11
Open

Create UserDAO.java#11
vivek-kumar-2024 wants to merge 1 commit intomainfrom
vivek-kumar-2024-patch-11

Conversation

@vivek-kumar-2024
Copy link
Owner

No description provided.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

New UserDAO.java file introduces critical security vulnerabilities and poor database handling practices that require immediate attention before merging.

  • SQL injection risk in query construction through string concatenation instead of using PreparedStatement
  • Security concern: Database credentials are hardcoded directly in source code
  • Resource leaks: Connection, Statement, and ResultSet not properly closed with try-with-resources
  • Error handling issues: Empty catch block silently suppresses SQLExceptions without logging
  • Missing proper data validation and return value handling for user information

1 file reviewed, 2 comments
Edit PR Review Bot Settings | Greptile

try {
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE username = '" + username + "'");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Critical SQL injection vulnerability. Use PreparedStatement instead:

Suggested change
ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE username = '" + username + "'");
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM users WHERE username = ?");
stmt.setString(1, username);
ResultSet rs = stmt.executeQuery();

Comment on lines +9 to +15
try {
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE username = '" + username + "'");
while (rs.next()) {
System.out.println(rs.getString("email"));
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Resources (Connection, Statement, ResultSet) must be closed. Use try-with-resources

Suggested change
try {
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE username = '" + username + "'");
while (rs.next()) {
System.out.println(rs.getString("email"));
}
try (Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE username = '" + username + "'")) {
while (rs.next()) {
System.out.println(rs.getString("email"));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant