Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,42 @@ public static void main(String[] args)
try {
String email = request.getParameter("email");
String token = request.getParameter("password");
// Use prepared statement to prevent SQL injection attacks
String sql = "select * from users where (email = ? and password = ?)";
connection = pool.getConnection();
statement = connection.prepareStatement(sql);
statement.setString(1, email);
statement.setString(2, token);

// Use role-based access controls
HttpSession session = request.getSession();
String role = (String)session.getAttribute("role");
if (role.equals(ADMIN)) {
ResultSet result = statement.executeQuery();
}

if (result.next()) {
loggedIn = true;
// Successfully logged in and redirect to user profile page

} else {
// Auth failure - Redirect to Login Page
}
}
catch (SQLException ex) {
handleExceptions(ex);
}
finally {
// Properly close resources to prevent resource leaks
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
}
}


String sql = "select * from users where (email ='" + email +"' and password ='" + token + "')";

Expand Down