From 3777317267a55edf7700b0fa9415fe07c0e25b9b Mon Sep 17 00:00:00 2001 From: Srushti Jiyani Date: Tue, 6 Oct 2026 16:19:02 -0400 Subject: [PATCH 1/6] Change database connection for login.jsp Updated database connection details for login functionality. --- src/main/webapp/login.jsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/login.jsp b/src/main/webapp/login.jsp index 8f4a4ba..ebae56b 100644 --- a/src/main/webapp/login.jsp +++ b/src/main/webapp/login.jsp @@ -3,7 +3,7 @@ String userName = request.getParameter("userName"); String password = request.getParameter("password"); Class.forName("com.mysql.jdbc.Driver"); - Connection con = DriverManager.getConnection("jdbc:mysql://mydb.c1g5t3oofrok.us-west-2.rds.amazonaws.com:3306/jwt","ravi", "Admin123*"); + Connection con = DriverManager.getConnection("jdbc:mysql://project-db.c6vg2sggyk5g.us-east-1.rds.amazonaws.com:3306/jwt","sru", "Admin123*"); Statement st = con.createStatement(); ResultSet rs; rs = st.executeQuery("select * from USER where userName='" +userName + "' and password='" +password + "'"); From a2f9e11d4355fac7c790770da2771e8a1adeb5ae Mon Sep 17 00:00:00 2001 From: Srushti Jiyani Date: Tue, 6 Oct 2026 16:20:57 -0400 Subject: [PATCH 2/6] Change database connection for user registration Updated database connection details for user registration. --- src/main/webapp/userRegistration.jsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/userRegistration.jsp b/src/main/webapp/userRegistration.jsp index 4c9142c..6ade615 100644 --- a/src/main/webapp/userRegistration.jsp +++ b/src/main/webapp/userRegistration.jsp @@ -6,7 +6,7 @@ String lastName = request.getParameter("lastName"); String email = request.getParameter("email"); Class.forName("com.mysql.jdbc.Driver"); - Connection con = DriverManager.getConnection("jdbc:mysql://mydb.c1g5t3oofrok.us-west-2.rds.amazonaws.com:3306/jwt", "ravi", "Admin123*"); + Connection con = DriverManager.getConnection("jdbc:mysql://project-db.c6vg2sggyk5g.us-east-1.rds.amazonaws.com:3306/jwt","admin", "#Sru1798"); Statement st = con.createStatement(); int i = st.executeUpdate("insert into USER(first_name, last_name, email, username, password, regdate) values ('" + firstName + "','" + lastName + "','" + email + "','" + userName + "','" + password + "', CURDATE())"); From 0b285204fbbe15069201e2e2af54e116ad8626a4 Mon Sep 17 00:00:00 2001 From: Srushti Jiyani Date: Tue, 6 Oct 2026 16:21:16 -0400 Subject: [PATCH 3/6] Change database credentials in login.jsp Updated database credentials and connection details in login.jsp. --- src/main/webapp/login.jsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/login.jsp b/src/main/webapp/login.jsp index ebae56b..b021cff 100644 --- a/src/main/webapp/login.jsp +++ b/src/main/webapp/login.jsp @@ -3,7 +3,7 @@ String userName = request.getParameter("userName"); String password = request.getParameter("password"); Class.forName("com.mysql.jdbc.Driver"); - Connection con = DriverManager.getConnection("jdbc:mysql://project-db.c6vg2sggyk5g.us-east-1.rds.amazonaws.com:3306/jwt","sru", "Admin123*"); + Connection con = DriverManager.getConnection("jdbc:mysql://project-db.c6vg2sggyk5g.us-east-1.rds.amazonaws.com:3306/jwt","admin", "#Sru1798"); Statement st = con.createStatement(); ResultSet rs; rs = st.executeQuery("select * from USER where userName='" +userName + "' and password='" +password + "'"); From 3ffd64ffbf91f064618ede07e9bcfe4cc067e75e Mon Sep 17 00:00:00 2001 From: Srushti Jiyani Date: Tue, 6 Oct 2026 20:41:16 -0400 Subject: [PATCH 4/6] Update MySQL connector and groupId in pom.xml Updated MySQL connector version and changed groupId. --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 1b0d4ad..0f3a1ca 100644 --- a/pom.xml +++ b/pom.xml @@ -18,9 +18,9 @@ provided - mysql - mysql-connector-java - 5.1.30 + com.mysql + mysql-connector-j + 8.4.0 junit From c1987e741391072e4de74f59f790ee8c6d0cadbf Mon Sep 17 00:00:00 2001 From: Srushti Jiyani Date: Wed, 7 Oct 2026 13:22:06 -0400 Subject: [PATCH 5/6] Update login.jsp for secure database access Refactor login logic to use PreparedStatement and environment variables for database connection. --- src/main/webapp/login.jsp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/webapp/login.jsp b/src/main/webapp/login.jsp index b021cff..cb7c021 100644 --- a/src/main/webapp/login.jsp +++ b/src/main/webapp/login.jsp @@ -1,16 +1,21 @@ <%@ page import="java.sql.*"%> <% - String userName = request.getParameter("userName"); + String userName = request.getParameter("userName"); String password = request.getParameter("password"); - Class.forName("com.mysql.jdbc.Driver"); - Connection con = DriverManager.getConnection("jdbc:mysql://project-db.c6vg2sggyk5g.us-east-1.rds.amazonaws.com:3306/jwt","admin", "#Sru1798"); - Statement st = con.createStatement(); - ResultSet rs; - rs = st.executeQuery("select * from USER where userName='" +userName + "' and password='" +password + "'"); - if (rs.next()) { - session.setAttribute("userName", userName); - response.sendRedirect("success.jsp"); - } else { - out.println("Invalid password try again"); + Class.forName("com.mysql.cj.jdbc.Driver"); + try (Connection con = DriverManager.getConnection( + System.getenv("DB_URL"), System.getenv("DB_USER"), System.getenv("DB_PASSWORD")); + PreparedStatement ps = con.prepareStatement( + "select * from USER where username=? and password=?")) { + ps.setString(1, userName); + ps.setString(2, password); + try (ResultSet rs = ps.executeQuery()) { + if (rs.next()) { + session.setAttribute("userName", userName); + response.sendRedirect("success.jsp"); + } else { + out.println("Invalid password try again"); + } + } } %> From 8b70f76f1b6d9f5e1d83d43c8968ba016de69725 Mon Sep 17 00:00:00 2001 From: Srushti Jiyani Date: Wed, 7 Oct 2026 13:22:27 -0400 Subject: [PATCH 6/6] Refactor user registration to use PreparedStatement Refactored user registration logic to use PreparedStatement for better security and maintainability. Updated JDBC driver and connection handling. --- src/main/webapp/userRegistration.jsp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/webapp/userRegistration.jsp b/src/main/webapp/userRegistration.jsp index 6ade615..1c0d573 100644 --- a/src/main/webapp/userRegistration.jsp +++ b/src/main/webapp/userRegistration.jsp @@ -1,19 +1,24 @@ <%@ page import="java.sql.*"%> <% - String userName = request.getParameter("userName"); + String userName = request.getParameter("userName"); String password = request.getParameter("password"); String firstName = request.getParameter("firstName"); String lastName = request.getParameter("lastName"); String email = request.getParameter("email"); - Class.forName("com.mysql.jdbc.Driver"); - Connection con = DriverManager.getConnection("jdbc:mysql://project-db.c6vg2sggyk5g.us-east-1.rds.amazonaws.com:3306/jwt","admin", "#Sru1798"); - Statement st = con.createStatement(); - int i = st.executeUpdate("insert into USER(first_name, last_name, email, username, password, regdate) values ('" + firstName + "','" - + lastName + "','" + email + "','" + userName + "','" + password + "', CURDATE())"); - if (i > 0) { - response.sendRedirect("welcome.jsp"); - - } else { - response.sendRedirect("index.jsp"); + Class.forName("com.mysql.cj.jdbc.Driver"); + try (Connection con = DriverManager.getConnection( + System.getenv("DB_URL"), System.getenv("DB_USER"), System.getenv("DB_PASSWORD")); + PreparedStatement ps = con.prepareStatement( + "insert into USER(first_name, last_name, email, username, password, regdate) values (?, ?, ?, ?, ?, CURDATE())")) { + ps.setString(1, firstName); + ps.setString(2, lastName); + ps.setString(3, email); + ps.setString(4, userName); + ps.setString(5, password); + if (ps.executeUpdate() > 0) { + response.sendRedirect("welcome.jsp"); + } else { + response.sendRedirect("index.jsp"); + } } %>