Project – How Facebook Login Works – JSP,Servlets

PROJECT IS DEVELOPED BY – MAHESH KARANDE

untitled


This Login Project works same as Official Facebook Login.

Once you Login in Facebook it’s never ask you to Re-login . Only when you clicked Signout option.

untitdled

Because you Clicked in Keep me logged in that’s way Facebook never ask you to Re-login. Because when you click here its create session for that particular user. I really dont  know how Facebook does but i created using session

 HttpSession localHttpSession = req.getSession();
	localHttpSession.setMaxInactiveInterval(20*60);

        localHttpSession.setAttribute("s1", s1);

So After Login Its Create Session for that particular user. If Keep me logged in is Checked.

If its not checked It will not create session for that user.

You will ask If Browser is Closed Session are Destroyed  but What i did, It will still maintain your Session even after your PC is Restarted or Shutdown.

While Login what i did ,  Created a Temporary Database(Table) and Save your Session their. After PC Restart or Browser Reopen Its Check Sessions in both Browser and Database. IF session are present in one of them Its automatically Re-login.

 Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "system");
      Statement stmt = conn.createStatement();
System.out.println("Creating table in given database...");
      stmt = conn.createStatement();
 String sql = "CREATE TABLE SESSIONS(SES VARCHAR(100))";
      stmt.executeUpdate(sql);
      System.out.println("Created table in given database...");
String sqll = "Insert  into SESSIONS(ses) values('" + s1 + "')";
  System.out.println("Statement executed " + sqll);

When you Logout

It Deletes All Session of Brower or Database.

try{
			Class.forName("oracle.jdbc.driver.OracleDriver");
			Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "system");
   			   Statement stmt = conn.createStatement();
				System.out.println("Creating table in given database...");
  				    stmt = conn.createStatement();
			 String sql = "DROP TABLE SESSIONS";
     			 stmt.executeUpdate(sql);
    			  System.out.println("DROPPED given database...");
		}
		catch (SQLException localSQLException)
    {
      localSQLException.printStackTrace();
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }

			HttpSession session=request.getSession();
			session.invalidate();

			out.print("You are successfully logged out!");

Main Code – in JSP FILE

If you want Full Project Comment Below.

Above Codes are Half Codes for Sample Purpose from my Project.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s