Solved

How to remember username and password

Posted on 2009-05-17
2
913 Views
Last Modified: 2012-05-07
Hi i am using a login page when the user wants the computer the remember his username and password he checks a checkbox and click enter.

So when next time he enters username the password will be automatically entered. I knw it can be done by cookies and i tried it but i am not sure with coding. So can u please help me wiht it.

Please suggest me a cookie solution only in JSP i dont want to use javascript here.
Code for Index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
 
     <form method="get" action="forum.jsp">
     
  <table align="center"><tbody>
  <tr><td></td></tr>
  <tr><td align="center">Welcome to My Orkut Forum</td></tr>
  <tr></tr></tbody>
  </table>
  <hr size="4"><br><br>
  <center>Please Login To Continue</center><br><br>
  <img src= "http://www.activefeeds.com/images/pic_login.jpg" align="left" width="500" height ="350" >
<table align="right">
<tbody bgcolor="#C3D9FF">
 
<tr>
<td>Enter User Id</td><td><input type="text" size="20" name="userId" /></td>
</tr>
<tr>
<td>Enter Password</td><td><input type="password" size="20" name="userPassword" /></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Login"/></td>
<td><input type="reset" name="reset" value="Reset"></td>
</tr>
<tr>
<td><input type="checkbox" name="rememberMe" id="rememberMe" /> Remember Me on this Computer</td>
</tr>
<tr>
<td>Not a member yet?<br>
  <a href="registration.jsp"><b>JOIN NOW</b></a>
  
</td>
</tr>
</table>
</form>
<br><br><br><br><br>
<br><br><br>
<br>
<table align ="right">
<tr>
<td>
<img src="http://www.asn-online.org/images/forgot-password-icon.png"/><a href="passwordReminder.jsp">Forgot your Password or Username
</a>
</td>
</tr>
</table>
</body>
</html>
 
 
 
 
Code for forum.jsp
 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%String userid = request.getParameter("userId");
String password = request.getParameter("userPassword");
String checkbox = request.getParameter("RememberMe");
 
if (!checkbox==null) {
Cookie c1 = new Cookie("userid", "userId");
Cookie c2 = new Cookie("password", "Password");
//CHECKBOX cb = new CHECKBOX("saveUserId", "true");
c1.setMaxAge(1000);
c2.setMaxAge(1000);
response.addCookie(c1);
response.addCookie(c2);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
response.sendRedirect("Welcome");
}
else {
sendLoginForm(response, true);
} %>
 
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
 
 
</body>
</html>

Open in new window

0
Comment
Question by:haribee2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
Gibu George earned 500 total points
ID: 24410375
0
 

Author Comment

by:haribee2000
ID: 24414587
Can you send me the code it will be more helpfull to me
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
 shows up in Outlook, not OWA or on phone 3 78
Using YubiKey with REST API application 2 136
Adjust the position 3 70
ejb on wildfly 5 46
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question