users can now login, ip address saved in db and users preferred settings are loaded (stored in config/[insert username here].ini)

hb2143 [2005-08-04 18:35:19]
users can now login, ip address saved in db and users preferred settings are loaded (stored in config/[insert username here].ini)
Filename
.classpath
.project
.settings/org.eclipse.jdt.ui.prefs
config/content extractor settings.ini
config/hilabecker.ini
config/sb.ini
src/psl/crunch3/Crunch3Settings.java
src/psl/crunch3/HttpStream.java
src/psl/crunch3/MainControl.java
src/psl/crunch3/Proxy.java
src/psl/crunch3/web/LoginServlet.java
src/psl/crunch3/web/RegisterBean.java
src/psl/crunch3/web/RegisterServlet.java
src/psl/crunch3/web/Test.java
website/success.jsp
diff --git a/.classpath b/.classpath
index 713c13f..a2dae70 100644
--- a/.classpath
+++ b/.classpath
@@ -9,10 +9,12 @@
 	<classpathentry kind="lib" path="jars/googleapi/googleapi.jar"/>
 	<classpathentry kind="lib" path="jars/jfreechart/jfreechart-0.9.21/jfreechart-0.9.21.jar"/>
 	<classpathentry kind="lib" path="jars/jfreechart/jfreechart-0.9.21/lib/jcommon-0.9.6.jar"/>
-	<classpathentry kind="lib" path="C:/Program Files/Tomcat 5.5/common/lib/servlet-api.jar"/>
-	<classpathentry kind="lib" path="C:/Program Files/Tomcat 5.5/common/lib/jasper-runtime.jar"/>
-	<classpathentry kind="lib" path="C:/Program Files/Tomcat 5.5/common/lib/jsp-api.jar"/>
-	<classpathentry kind="lib" path="C:/Program Files/Tomcat 5.5/common/lib/jstl.jar"/>
-	<classpathentry kind="lib" path="C:/Program Files/Tomcat 5.5/common/lib/standard.jar"/>
+	<classpathentry kind="lib" path="/usr/local/jakarta-tomcat-5.5.9/common/lib/servlet-api.jar"/>
+	<classpathentry kind="lib" path="/usr/local/jakarta-tomcat-5.5.9/common/lib/jasper-runtime.jar"/>
+	<classpathentry kind="lib" path="/usr/local/jakarta-tomcat-5.5.9/common/lib/jsp-api.jar"/>
+	<classpathentry kind="lib" path="/usr/local/jakarta-tomcat-5.5.9/common/lib/jstl.jar"/>
+	<classpathentry kind="lib" path="/usr/local/jakarta-tomcat-5.5.9/common/lib/standard.jar"/>
+	<classpathentry kind="lib" path="/usr/local/jakarta-tomcat-5.5.9/common/lib/mysql-connector-java-3.1.10-bin.jar"/>
+	<classpathentry kind="lib" path="/usr/local/jakarta-tomcat-5.5.9/common/lib/mm.mysql-2.0.13-bin.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/.project b/.project
index 4089ee5..477132b 100644
--- a/.project
+++ b/.project
@@ -27,12 +27,12 @@
 		<link>
 			<name>output</name>
 			<type>2</type>
-			<location>C:/Program Files/Tomcat 5.5/webapps/Crunch/WEB-INF/classes</location>
+			<location>/usr/local/jakarta-tomcat-5.5.9/webapps/crunch/WEB-INF/classes</location>
 		</link>
 		<link>
 			<name>Crunch_WebApp</name>
 			<type>2</type>
-			<location>C:/Program Files/Tomcat 5.5/webapps/Crunch</location>
+			<location>/usr/local/jakarta-tomcat-5.5.9/webapps/crunch</location>
 		</link>
 	</linkedResources>
 </projectDescription>
diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..91bf649
--- /dev/null
+++ b/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,3 @@
+#Tue Aug 02 16:46:34 EDT 2005
+eclipse.preferences.version=1
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates/>
diff --git a/config/content extractor settings.ini b/config/content extractor settings.ini
index 642ec10..da9e4b6 100644
--- a/config/content extractor settings.ini
+++ b/config/content extractor settings.ini
@@ -1,42 +1,42 @@
-#Content Extractor Settings File
-#Sun Jul 31 18:45:28 EDT 2005
-<A>\ tags\ are\ substance=true
-<FORM>\ tags\ are\ substance=true
-Ignore\ Image\ Links=true
-Ignore\ Meta\ Tags=true
-Display\ Image\ Link\ ALTs=true
-Ignore\ Text\ Links=true
-<INPUT>\ tags\ are\ substance=true
-Ignore\ <IFRAME>\ Tags=true
-<BUTTON>\ tags\ are\ substance=true
-Ignore\ All\ Advertisements=true
-<SELECT>\ tags\ are\ substance=true
-Ignore\ External\ Stylesheets=true
-<IFRAME>\ tags\ are\ substance=true
-Ignore\ <EMBED>\ tags=true
-Ignore\ Styles=true
-Ignore\ Only\ Links\ and\ Text\ in\ Link\ Lists=true
-Ignore\ <INPUT>\ Tags=true
-Ignore\ Flash=true
-Ignore\ Image\ Links\ in\ Link\ Lists=true
-<IMG>\ tags\ are\ substance=true
-<TEXTAREA>\ tags\ are\ substance=true
-Ignore\ Scripts=true
-Ignore\ Forms=true
-Display\ Image\ ALTs=true
-Maximum\ Number\ of\ Line\ Breaks=2
-Ignore\ <BUTTON>\ Tags=true
-Limit\ Number\ of\ Line\ Breaks=false
-Ignore\ Style\ Attribute\ in\ <DIV>\ Tags=true
-Ignore\ <NOSCRIPT>\ Tags=true
-Add\ removed\ links\ to\ bottom\ of\ the\ page=false
-Minimum\ text\ length\ as\ substance=12
-Remove\ Empty\ Tables=true
-Ignore\ Text\ Links\ in\ Link\ Lists=true
-Ignore\ Table\ Cell\ Widths=true
-Ignore\ Style\ Attributes=true
-Ignore\ <SELECT>\ Tags=true
-Link/Text\ Removal\ Ratio=0.25
-Ignore\ Images=true
-Ignore\ Link\ Lists=true
-Print\ Only\ Text=false
+#Content Extractor Settings File
+#Thu Aug 04 14:30:15 EDT 2005
+<A>\ tags\ are\ substance=true
+<FORM>\ tags\ are\ substance=true
+Ignore\ Image\ Links=false
+Ignore\ Meta\ Tags=true
+Display\ Image\ Link\ ALTs=true
+Ignore\ Text\ Links=false
+<INPUT>\ tags\ are\ substance=true
+Ignore\ <IFRAME>\ Tags=true
+<BUTTON>\ tags\ are\ substance=true
+Ignore\ All\ Advertisements=true
+<SELECT>\ tags\ are\ substance=true
+Ignore\ External\ Stylesheets=false
+<IFRAME>\ tags\ are\ substance=true
+Ignore\ <EMBED>\ tags=true
+Ignore\ Styles=false
+Ignore\ Only\ Links\ and\ Text\ in\ Link\ Lists=true
+Ignore\ <INPUT>\ Tags=true
+Ignore\ Flash=true
+Ignore\ Image\ Links\ in\ Link\ Lists=true
+<IMG>\ tags\ are\ substance=true
+<TEXTAREA>\ tags\ are\ substance=true
+Ignore\ Scripts=true
+Ignore\ Forms=false
+Display\ Image\ ALTs=true
+Maximum\ Number\ of\ Line\ Breaks=2
+Ignore\ <BUTTON>\ Tags=false
+Limit\ Number\ of\ Line\ Breaks=false
+Ignore\ Style\ Attribute\ in\ <DIV>\ Tags=false
+Ignore\ <NOSCRIPT>\ Tags=true
+Add\ removed\ links\ to\ bottom\ of\ the\ page=false
+Minimum\ text\ length\ as\ substance=12
+Remove\ Empty\ Tables=false
+Ignore\ Text\ Links\ in\ Link\ Lists=true
+Ignore\ Table\ Cell\ Widths=true
+Ignore\ Style\ Attributes=false
+Ignore\ <SELECT>\ Tags=true
+Link/Text\ Removal\ Ratio=0.75
+Ignore\ Images=false
+Ignore\ Link\ Lists=false
+Print\ Only\ Text=false
diff --git a/config/hilabecker.ini b/config/hilabecker.ini
new file mode 100644
index 0000000..c7997f4
--- /dev/null
+++ b/config/hilabecker.ini
@@ -0,0 +1,42 @@
+#Content Extractor Settings File
+#Thu Feb 10 18:58:56 EST 2005
+<A>\ tags\ are\ substance=true
+<FORM>\ tags\ are\ substance=true
+Ignore\ Image\ Links=false
+Ignore\ Meta\ Tags=true
+Display\ Image\ Link\ ALTs=true
+Ignore\ Text\ Links=false
+<INPUT>\ tags\ are\ substance=true
+Ignore\ <IFRAME>\ Tags=true
+<BUTTON>\ tags\ are\ substance=true
+Ignore\ All\ Advertisements=true
+<SELECT>\ tags\ are\ substance=true
+Ignore\ External\ Stylesheets=false
+<IFRAME>\ tags\ are\ substance=true
+Ignore\ <EMBED>\ tags=true
+Ignore\ Styles=false
+Ignore\ Only\ Links\ and\ Text\ in\ Link\ Lists=true
+Ignore\ <INPUT>\ Tags=true
+Ignore\ Flash=true
+Ignore\ Image\ Links\ in\ Link\ Lists=true
+<IMG>\ tags\ are\ substance=true
+<TEXTAREA>\ tags\ are\ substance=true
+Ignore\ Scripts=true
+Ignore\ Forms=false
+Display\ Image\ ALTs=true
+Maximum\ Number\ of\ Line\ Breaks=2
+Ignore\ <BUTTON>\ Tags=false
+Limit\ Number\ of\ Line\ Breaks=false
+Ignore\ Style\ Attribute\ in\ <DIV>\ Tags=false
+Ignore\ <NOSCRIPT>\ Tags=true
+Add\ removed\ links\ to\ bottom\ of\ the\ page=false
+Minimum\ text\ length\ as\ substance=12
+Remove\ Empty\ Tables=false
+Ignore\ Text\ Links\ in\ Link\ Lists=true
+Ignore\ Table\ Cell\ Widths=true
+Ignore\ Style\ Attributes=false
+Ignore\ <SELECT>\ Tags=true
+Ignore\ Link\ Lists=false
+Link/Text\ Removal\ Ratio=0.75
+Ignore\ Images=false
+Print\ Only\ Text=false
diff --git a/config/sb.ini b/config/sb.ini
new file mode 100644
index 0000000..c7997f4
--- /dev/null
+++ b/config/sb.ini
@@ -0,0 +1,42 @@
+#Content Extractor Settings File
+#Thu Feb 10 18:58:56 EST 2005
+<A>\ tags\ are\ substance=true
+<FORM>\ tags\ are\ substance=true
+Ignore\ Image\ Links=false
+Ignore\ Meta\ Tags=true
+Display\ Image\ Link\ ALTs=true
+Ignore\ Text\ Links=false
+<INPUT>\ tags\ are\ substance=true
+Ignore\ <IFRAME>\ Tags=true
+<BUTTON>\ tags\ are\ substance=true
+Ignore\ All\ Advertisements=true
+<SELECT>\ tags\ are\ substance=true
+Ignore\ External\ Stylesheets=false
+<IFRAME>\ tags\ are\ substance=true
+Ignore\ <EMBED>\ tags=true
+Ignore\ Styles=false
+Ignore\ Only\ Links\ and\ Text\ in\ Link\ Lists=true
+Ignore\ <INPUT>\ Tags=true
+Ignore\ Flash=true
+Ignore\ Image\ Links\ in\ Link\ Lists=true
+<IMG>\ tags\ are\ substance=true
+<TEXTAREA>\ tags\ are\ substance=true
+Ignore\ Scripts=true
+Ignore\ Forms=false
+Display\ Image\ ALTs=true
+Maximum\ Number\ of\ Line\ Breaks=2
+Ignore\ <BUTTON>\ Tags=false
+Limit\ Number\ of\ Line\ Breaks=false
+Ignore\ Style\ Attribute\ in\ <DIV>\ Tags=false
+Ignore\ <NOSCRIPT>\ Tags=true
+Add\ removed\ links\ to\ bottom\ of\ the\ page=false
+Minimum\ text\ length\ as\ substance=12
+Remove\ Empty\ Tables=false
+Ignore\ Text\ Links\ in\ Link\ Lists=true
+Ignore\ Table\ Cell\ Widths=true
+Ignore\ Style\ Attributes=false
+Ignore\ <SELECT>\ Tags=true
+Ignore\ Link\ Lists=false
+Link/Text\ Removal\ Ratio=0.75
+Ignore\ Images=false
+Print\ Only\ Text=false
diff --git a/src/psl/crunch3/Crunch3Settings.java b/src/psl/crunch3/Crunch3Settings.java
index 22cf4eb..df99a09 100644
--- a/src/psl/crunch3/Crunch3Settings.java
+++ b/src/psl/crunch3/Crunch3Settings.java
@@ -29,6 +29,7 @@ public class Crunch3Settings {
 	public static final boolean PROXY_MODE_DEF = true;
 	public static String SETTINGS_FILE = "config/content extractor settings.ini";
 	public static final boolean CHECK_HOMEPAGE_DEF = false;
+	public static final boolean RUN_ON_SERVER = true;

 	//internal variables
 	private String[] arguments;
diff --git a/src/psl/crunch3/HttpStream.java b/src/psl/crunch3/HttpStream.java
index 3335328..b1f026d 100644
--- a/src/psl/crunch3/HttpStream.java
+++ b/src/psl/crunch3/HttpStream.java
@@ -4,6 +4,7 @@
  */
 package psl.crunch3;

+import java.sql.*;
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -56,6 +57,9 @@ public class HttpStream extends Thread {

 	private String status;

+	private Connection con;
+
+
 	public HttpStream(final Socket socket) {
 		super("HttpStreamThread");
 		if (socket == null)
@@ -78,6 +82,11 @@ public class HttpStream extends Thread {
 					+ "\n");
 		}

+
+		//get associated username with client InetAddress
+		if(Crunch3.settings.RUN_ON_SERVER){
+			getUsernameFromDB();
+		}
 		this.start();
 	}

@@ -618,5 +627,46 @@ public class HttpStream extends Thread {
 	public void setStatus(final String status) {
 		this.status = status;
 	}
+
+	/**
+	 * connects to the database and fetches the username that is associated with the IP address
+	 * of the client
+	 */
+	private void getUsernameFromDB(){
+		con = Crunch3.proxy.getConnection();
+		Statement stmt = null;
+		ResultSet rs = null;
+
+		if (Crunch3.settings.isVerbose()){
+    		System.out.println("changing settings");
+    		System.out.println();
+    	}
+		System.out.println("********************working working");
+
+		if(con != null){
+			try{
+				System.out.println("**********");
+				stmt = con.createStatement();
+
+	            stmt.execute("select user from connected where ip='" + clientSocket.getInetAddress() + "'");
+
+	            rs= stmt.getResultSet();
+	            if(!rs.next()){
+	            	//load default settings
+	            }
+	            else{
+	            	String username=rs.getString(1);
+	            	Crunch3.mainControl.loadFile("config" +File.separator+ username+".ini");
+	            	if (Crunch3.settings.isVerbose()){
+	            		System.out.println("settings file loaded for user " + username);
+	            	}
+	            }
+			}
+			catch(Exception e){
+				e.printStackTrace();
+			}
+
+		}
+	}

 }
diff --git a/src/psl/crunch3/MainControl.java b/src/psl/crunch3/MainControl.java
index 84a918c..4707cb4 100644
--- a/src/psl/crunch3/MainControl.java
+++ b/src/psl/crunch3/MainControl.java
@@ -159,6 +159,7 @@ public class MainControl extends Thread{
 	public void loadFile(String file){

 		//try to read the file
+		System.out.println("changing settings from loadFile ******");
 		try{

 			FileReader reader = new FileReader(file);
diff --git a/src/psl/crunch3/Proxy.java b/src/psl/crunch3/Proxy.java
index 31ee0b9..00deab8 100644
--- a/src/psl/crunch3/Proxy.java
+++ b/src/psl/crunch3/Proxy.java
@@ -4,6 +4,7 @@
  */
 package psl.crunch3;
 import java.util.*;
+import java.sql.*;
 import java.net.*;
 import java.io.*;

@@ -24,6 +25,8 @@ public class Proxy implements Runnable {
 	//private LinkedList transfers;
 	private Vector<ProxyFilter> plugins = new Vector<ProxyFilter>();

+	private Connection con = null;
+
 	public Proxy(int port) {
 		//ensure the port given is in the proper range
 		if (port < 0 || port > 65536) {
@@ -189,4 +192,38 @@ public class Proxy implements Runnable {

 		return pfArray;
 	}
+
+	/**
+	 * returns a Connection object that connnects to the crunch database
+	 */
+	public Connection getConnection(){
+
+		if(con == null){
+			//connect to DB
+			 try {
+
+
+				 //Register the JDBC driver for MySQL.
+
+
+				 Class.forName("org.gjt.mm.mysql.Driver");
+
+			     String url = "jdbc:mysql://localhost:3306/crunch";
+
+				 System.out.println("point 2");
+
+		        con = DriverManager.getConnection(url, "admin", "test");
+
+		     }
+			 catch (Exception ex) {
+
+				 	con=null;
+				 	ex.printStackTrace();
+		     }
+
+
+		}
+		return con;
+	}
+
 }
diff --git a/src/psl/crunch3/web/LoginServlet.java b/src/psl/crunch3/web/LoginServlet.java
new file mode 100644
index 0000000..8bb9a79
--- /dev/null
+++ b/src/psl/crunch3/web/LoginServlet.java
@@ -0,0 +1,53 @@
+package psl.crunch3.web;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+
+import java.io.*;
+import java.net.InetAddress;
+import java.util.*;
+
+
+public class LoginServlet extends HttpServlet{
+
+
+
+	public void doGet(HttpServletRequest request, HttpServletResponse response)
+    throws ServletException, IOException {
+
+	//get the bean for this session
+		HttpSession s = request.getSession(true);
+		RegisterBean lb = (RegisterBean)s.getAttribute("information");
+		if (lb==null){
+			lb = new RegisterBean();
+			s.setAttribute("lb", lb);
+		}
+
+		lb.setUsername((request.getParameter("username")));
+	    lb.setPassword((request.getParameter("password")));
+
+			Cookie c = new Cookie("crunch", lb.getUsername());
+        	InetAddress remoteInetAddress = InetAddress.getByName(request.getRemoteAddr());
+        if(lb.authenticate(remoteInetAddress)){
+        	lb.login(remoteInetAddress);
+        	response.addCookie(c);
+			RequestDispatcher r = getServletContext().getRequestDispatcher(
+	          "/interface.htm");
+	        r.forward(request, response);
+		}
+		else{
+			RequestDispatcher r = getServletContext().getRequestDispatcher(
+	          "/login.htm");
+	        r.forward(request, response);
+		}
+
+	}
+
+	  public void doPost(HttpServletRequest request, HttpServletResponse response)
+	  	throws ServletException, IOException {
+		  doGet(request, response);
+	  }
+
+
+}
diff --git a/src/psl/crunch3/web/RegisterBean.java b/src/psl/crunch3/web/RegisterBean.java
index 5ebdecf..b2b36c2 100644
--- a/src/psl/crunch3/web/RegisterBean.java
+++ b/src/psl/crunch3/web/RegisterBean.java
@@ -1,6 +1,8 @@
 package psl.crunch3.web;

 import java.io.*;
+import java.net.InetAddress;
+import java.security.*;
 import java.sql.*;

 public class RegisterBean implements Serializable{
@@ -8,6 +10,23 @@ public class RegisterBean implements Serializable{
 	private String firstName, lastName, email;
 	private String username, password;
 	private String repeat, firstValid, lastValid, emailValid, userValid,passValid;
+	private String inserted;
+	private Connection conn;
+
+	public RegisterBean(){
+		connect();
+	}
+
+	private void connect(){
+		try{
+			Class.forName("org.gjt.mm.mysql.Driver");
+			String url = "jdbc:mysql://localhost:3306/crunch";
+			conn = DriverManager.getConnection(url, "admin", "test");
+		}
+		catch(Exception e){
+			e.printStackTrace();
+		}
+	}


 	public void setFirstName(String newName){
@@ -69,9 +88,9 @@ public class RegisterBean implements Serializable{
 	public String getUserValid(){
 		return userValid;
 	}
-
-	//TODO: write a method to write to database, check that there are no duplicates
-	//reading from file for now
+	public String getInserted(){
+		return inserted;
+	}


 	/** form validation methods **/
@@ -129,6 +148,11 @@ public class RegisterBean implements Serializable{
 	           return false;

 	     }
+
+	     if(exists(username)){
+	    	 return false;
+	     }
+
 	     return true;

 	   }
@@ -156,17 +180,17 @@ public class RegisterBean implements Serializable{
 			 password = "";
 			 return false;
 		 }
-		 if(!isPasswordValid()){
-			 passValid= "false";
+
+		 if(!isUsernameValid()){
+			 userValid= "false";
 			 password = "";
 			 return false;
 		 }
-		 if(!isUsernameValid()){
-			 userValid= "false";
+		 if(!isPasswordValid()){
+			 passValid= "false";
 			 password = "";
 			 return false;
 		 }
-
 		 return true;
 	 }

@@ -179,31 +203,61 @@ public class RegisterBean implements Serializable{

 		 Statement stmt = null;
 		 ResultSet rs = null;
+

 		 try {
-
-			 //Register the JDBC driver for MySQL.
-			 //Class.forName("com.mysql.jdbc.Driver");
-
-
-			 String url = "jdbc:mysql://localhost:3306/mysql";
+
+			   if(conn==null) connect();
+	            stmt = conn.createStatement();
+
+	            stmt.execute("insert into user values ('" + username + "' , '"+
+	            		firstName + "' , '"+ lastName + "' , '"+ email + "' , '"+
+	            		encrypt(password) + "')");
+	            inserted="true";
+	            return true;
+

+	     }
+		 catch (Exception ex) {
+			 inserted="false";
+			 return false;
+	     }
+
+	 }
+
+
+	 /**
+	  * checks if name is already a username in the database
+	  * @param name
+	  * @return
+	  */
+	public boolean exists(String name){
+
+		Statement stmt = null;
+		ResultSet rs = null;


-	            Connection conn = DriverManager.getConnection(url, "admin", "CrTH3W#cH");
+		 try {
+
+
+
+			   if(conn==null) connect();
+
 	            stmt = conn.createStatement();
-	            //rs = stmt.executeQuery("");
+
+	            stmt.execute("select username from user where username='" + name + "'");
+
+	            rs= stmt.getResultSet();
+	            if (!rs.next()) return false;
+
+

 	     }
 		 catch (Exception ex) {
-	            return false;
+			 return true;
 	     }
 		 finally {
-			    // it is a good idea to release
-			    // resources in a finally{} block
-			    // in reverse-order of their creation
-			    // if they are no-longer needed
-
+
 			    if (rs != null) {
 			        try {
 			            rs.close();
@@ -222,14 +276,123 @@ public class RegisterBean implements Serializable{
 			}
 		  }
 		}
+		return true;
+
+	}
+
+
+	/**
+	 * encrypts x using MD5 encryption
+	 * @param x
+	 * @return the encrypted String
+	 * @throws Exception
+	 */
+	 public String encrypt(String x) throws Exception
+	 {
+		 java.security.MessageDigest d = java.security.MessageDigest.getInstance("MD5");
+		 d.reset();
+		 d.update(x.getBytes());
+		 return new String(d.digest());

-
-		 return true;
 	 }
-


-	 public boolean login(){
+
+	 public boolean authenticate(InetAddress address){
+		 Statement stmt = null;
+		 ResultSet rs = null;
+
+		 try {
+
+
+
+			   if(conn==null) connect();
+
+	            stmt = conn.createStatement();
+
+	            stmt.execute("select password from user where username='" + username +  "'");
+	            rs = stmt.getResultSet();
+
+	            if(!rs.next()){
+	            	return false;
+	            }
+	            else{
+	            	if( !(rs.getString(1)).equals(password))
+	            		return false;
+	            }
+
+
+	            //remove row from connected table
+	            stmt = conn.createStatement();
+
+	            stmt.execute("delete from connected where user='" + username +  "'");
+
+
+	            //remove all users from the same ip from connected table
+	            stmt = conn.createStatement();
+
+	            stmt.execute("delete from connected where ip='" + address +  "'");
+
+
+	     }
+		 catch (Exception ex) {
+			 return false;
+	     }
+		 finally {
+
+
+			    if (stmt != null) {
+			        try {
+			            stmt.close();
+			        } catch (SQLException sqlEx) { // ignore }
+
+			        stmt = null;
+			    }
+			}
+
+		}
 		 return true;
+
+
+	 }
+
+	 public boolean login(InetAddress address){
+
+		 Statement stmt = null;
+
+			 try {
+
+
+
+				   if(conn==null) connect();
+
+		            stmt = conn.createStatement();
+
+		            stmt.execute("insert into connected values ('" + username + "' , '"+
+		            		address + "')");
+
+
+
+
+
+
+		     }
+			 catch (Exception ex) {
+				 return false;
+		     }
+			 finally {
+
+
+				    if (stmt != null) {
+				        try {
+				            stmt.close();
+				        } catch (SQLException sqlEx) { // ignore }
+
+				        stmt = null;
+				    }
+				}
+
+			}
+			 return true;
 	 }
 }
diff --git a/src/psl/crunch3/web/RegisterServlet.java b/src/psl/crunch3/web/RegisterServlet.java
index 5898a7b..79bc4a4 100644
--- a/src/psl/crunch3/web/RegisterServlet.java
+++ b/src/psl/crunch3/web/RegisterServlet.java
@@ -3,7 +3,9 @@ package psl.crunch3.web;
 import javax.servlet.*;
 import javax.servlet.http.*;

+
 import java.io.*;
+import java.net.InetAddress;
 import java.util.*;

 public class RegisterServlet extends HttpServlet{
@@ -55,14 +57,22 @@ public class RegisterServlet extends HttpServlet{
 	        r.forward(request, response);
 	    }
 	    else{
-	    	response.setContentType(CONTENT_TYPE);
-
-	        PrintWriter out = response.getWriter();
-	        out.println(DOC_TYPE);
-	        out.println("<html>");
-	        out.println("<head> <title>" + "</title> </head>");
-	        out.println("<body> <H2> " + "Changes Submitted</H2> </body></html>");

+
+	        if(rb.writeToDB()){
+
+	        	Cookie c = new Cookie("crunch", rb.getUsername());
+	        	InetAddress remoteInetAddress = InetAddress.getByName(request.getRemoteAddr());
+	        	rb.login(remoteInetAddress);
+	        	response.addCookie(c);
+	        	RequestDispatcher r = getServletContext().getRequestDispatcher(
+		          "/success.jsp");
+		        r.forward(request, response);
+	        }
+	        else {RequestDispatcher r = getServletContext().getRequestDispatcher(
+	          "/Register.jsp");
+	        r.forward(request, response);
+	        }
 	    }


diff --git a/src/psl/crunch3/web/Test.java b/src/psl/crunch3/web/Test.java
new file mode 100644
index 0000000..16364d1
--- /dev/null
+++ b/src/psl/crunch3/web/Test.java
@@ -0,0 +1,77 @@
+package psl.crunch3.web;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class Test {
+
+	public static void main(String[] args){
+
+		Statement stmt = null;
+		 ResultSet rs = null;
+		 String username = "suhit";
+		 String firstName = "suhit";
+		 String lastName = "gupta";
+		 String email = "suhit@aol.com";
+		 String password = "hilaiscool";
+
+		 try {
+
+
+			 //Register the JDBC driver for MySQL.
+			System.out.println("starting");
+			 //Class.forName("com.mysql.jdbc.Driver");
+		     Class.forName("org.gjt.mm.mysql.Driver");
+
+		     System.out.println("point 1");
+			 String url = "jdbc:mysql://localhost:3306/crunch";
+
+			 System.out.println("point 2");
+
+	            Connection conn = DriverManager.getConnection(url, "admin", "test");
+	            stmt = conn.createStatement();
+	            System.out.println("point 3");
+	            String str = ("insert into user values ('" + username + "' , '"+
+	            		firstName + "' , '"+ lastName + "' , '"+ email + "' , '"+
+	            		password + "')");
+	            System.out.println(str);
+	            stmt.execute(str);
+	            System.out.println("point 4");
+
+	     }
+		 catch (Exception ex) {
+
+			 	System.out.println(ex.getMessage());
+	            ex.getStackTrace();
+	     }
+		 finally {
+			    // it is a good idea to release
+			    // resources in a finally{} block
+			    // in reverse-order of their creation
+			    // if they are no-longer needed
+
+			    if (rs != null) {
+			        try {
+			            rs.close();
+			        } catch (SQLException sqlEx) { // ignore }
+
+			        rs = null;
+			    }
+
+			    if (stmt != null) {
+			        try {
+			            stmt.close();
+			        } catch (SQLException sqlEx) { // ignore }
+
+			        stmt = null;
+			    }
+			}
+		  }
+		}
+
+	}
+
+}
diff --git a/website/success.jsp b/website/success.jsp
new file mode 100644
index 0000000..47f1a51
--- /dev/null
+++ b/website/success.jsp
@@ -0,0 +1,116 @@
+<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<jsp:useBean id="rb" scope="session" class="psl.crunch3.web.RegisterBean" />
+<title>Crunch - Register </title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<link href="crunch.css" rel="stylesheet" type="text/css">
+<script language="JavaScript" type="text/JavaScript">
+<!--
+
+<!--
+function MM_preloadImages() { //v3.0
+  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
+    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
+    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
+}
+
+function MM_findObj(n, d) { //v4.01
+  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
+    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
+  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
+  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
+  if(!x && d.getElementById) x=d.getElementById(n); return x;
+}
+
+function MM_nbGroup(event, grpName) { //v6.0
+  var i,img,nbArr,args=MM_nbGroup.arguments;
+  if (event == "init" && args.length > 2) {
+    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
+      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
+      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
+      nbArr[nbArr.length] = img;
+      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
+        if (!img.MM_up) img.MM_up = img.src;
+        img.src = img.MM_dn = args[i+1];
+        nbArr[nbArr.length] = img;
+    } }
+  } else if (event == "over") {
+    document.MM_nbOver = nbArr = new Array();
+    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
+      if (!img.MM_up) img.MM_up = img.src;
+      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
+      nbArr[nbArr.length] = img;
+    }
+  } else if (event == "out" ) {
+    for (i=0; i < document.MM_nbOver.length; i++) {
+      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
+  } else if (event == "down") {
+    nbArr = document[grpName];
+    if (nbArr)
+      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
+    document[grpName] = nbArr = new Array();
+    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
+      if (!img.MM_up) img.MM_up = img.src;
+      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
+      nbArr[nbArr.length] = img;
+  } }
+}
+//-->
+</script>
+</head>
+
+<body onLoad="MM_preloadImages('images/menu_r1_c1_f3.gif','images/menu_r1_c1_f2.gif','images/menu_r1_c2_f3.gif','images/menu_r1_c2_f2.gif','images/menu_r1_c3_f3.gif','images/menu_r1_c3_f2.gif','images/menu_r1_c4_f3.gif','images/menu_r1_c4_f2.gif','images/menu_r1_c5_f3.gif','images/menu_r1_c5_f2.gif')">
+<div id="wrapper"> <br/>
+  <img src="title.png" width="740" height="124">
+  <table  align="center" border="0" cellpadding="0" cellspacing="0" width="740">
+    <!-- fwtable fwsrc="menu.png" fwbase="menu.gif" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
+    <tr>
+      <td><img src="images/spacer.gif" width="148" height="1" border="0" alt=""></td>
+      <td><img src="images/spacer.gif" width="148" height="1" border="0" alt=""></td>
+      <td><img src="images/spacer.gif" width="148" height="1" border="0" alt=""></td>
+      <td><img src="images/spacer.gif" width="148" height="1" border="0" alt=""></td>
+      <td><img src="images/spacer.gif" width="148" height="1" border="0" alt=""></td>
+      <td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
+    </tr>
+    <tr>
+      <td><a href="about.htm" target="_top" onClick="MM_nbGroup('down','navbar1','menu_r1_c1','images/menu_r1_c1_f3.gif',1);" onMouseOver="MM_nbGroup('over','menu_r1_c1','images/menu_r1_c1_f2.gif','images/menu_r1_c1_f3.gif',1);" onMouseOut="MM_nbGroup('out');"><img name="menu_r1_c1" src="images/menu_r1_c1.gif" width="148" height="30" border="0" alt=""></a></td>
+      <td><a href="people.htm" target="_top" onClick="MM_nbGroup('down','navbar1','menu_r1_c2','images/menu_r1_c2_f3.gif',1);" onMouseOver="MM_nbGroup('over','menu_r1_c2','images/menu_r1_c2_f2.gif','images/menu_r1_c2_f3.gif',1);" onMouseOut="MM_nbGroup('out');"><img name="menu_r1_c2" src="images/menu_r1_c2.gif" width="148" height="30" border="0" alt=""></a></td>
+      <td><a href="publications.htm" target="_top" onClick="MM_nbGroup('down','navbar1','menu_r1_c3','images/menu_r1_c3_f3.gif',1);" onMouseOver="MM_nbGroup('over','menu_r1_c3','images/menu_r1_c3_f2.gif','images/menu_r1_c3_f3.gif',1);" onMouseOut="MM_nbGroup('out');"><img name="menu_r1_c3" src="images/menu_r1_c3.gif" width="148" height="30" border="0" alt=""></a></td>
+      <td><a href="software.htm" target="_top" onClick="MM_nbGroup('down','navbar1','menu_r1_c4','images/menu_r1_c4_f3.gif',1);" onMouseOver="MM_nbGroup('over','menu_r1_c4','images/menu_r1_c4_f2.gif','images/menu_r1_c4_f3.gif',1);" onMouseOut="MM_nbGroup('out');"><img name="menu_r1_c4" src="images/menu_r1_c4.gif" width="148" height="30" border="0" alt=""></a></td>
+      <td><a href="register.htm" target="_top" onClick="MM_nbGroup('down','navbar1','menu_r1_c5','images/menu_r1_c5_f3.gif',1);" onMouseOver="MM_nbGroup('over','menu_r1_c5','images/menu_r1_c5_f2.gif','images/menu_r1_c5_f3.gif',1);" onMouseOut="MM_nbGroup('out');"><img name="menu_r1_c5" src="images/menu_r1_c5.gif" width="148" height="30" border="0" alt=""></a></td>
+      <td><img src="images/spacer.gif" width="1" height="30" border="0" alt=""></td>
+    </tr>
+  </table>
+  <div class="box" >
+  <div class="bi">
+		<div class="bt"><div></div></div>
+
+      <h1>Thank You</h1>
+
+      <p>&nbsp;</p>
+
+	  <p> Thank You <jsp:getProperty name="rb" property="firstName"/> <jsp:getProperty name="rb" property="lastName"/>, you have successfully registered
+		</p>
+
+
+      <p>&nbsp;</p>
+      <p>&nbsp;</p>
+      <p>&nbsp;</p>
+      <p align="center"><a href="index.html">Home</a> | <a href="about.htm">About</a>
+        | <a href="people.htm">People</a> | <a href="publications.htm">Publications</a>
+        | <a href="software.htm">Software</a> | <a href="register.htm">Register</a></p>
+		<div></div>
+		<div class="bb"><div></div></div></div>
+</div>
+  <div>
+    <div align="center">Copyright (c) 2005: The Trustees of Columbia University
+      in the City of New York. All Rights Reserved.</div>
+  </div>
+
+</div>
+
+
+</body>
+</html>
\ No newline at end of file