In this article, I am going to explain how to implement Remember Me checkbox functionality and simple login page code in asp. net. Remember me checkbox will maintain username and password for user when user visits next time.
To create the simple login page with remember password do the following.
First of all open a web site in ASP.Net and add some simple ASP.Net code within the default.aspx page. For example I must insert two TextBoxes, one for the userid and another for the password and one checkbox control that allows the user to specify whether he wants the page to remember the username and password when he visits the next time and one login button.
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- Userid:
- <asp:TextBox ID ="textbox1" runat ="server" ></asp:TextBox><br />
- Password:
- <asp:TextBox ID ="textbox2" runat ="server" TextMode ="Password" ></asp:TextBox><br />
- <asp:CheckBox ID ="rememberme" runat="server" Text ="remember Password" /><br />
- <asp:Button ID ="Login" runat ="server" Text ="Login" onclick="Login_Click" />
- </form>
- </body>
Save Userid and Password in cookie
Now the login button is clicked where I have login page code that stores the userid and password in a cookie. To do that, first dtermine if the remember me checkbox is checked. If it is checked then store the username and password into the cookie for the next 15 days from the current date. And if not checked then set the expiration date to 1 day in the future to destroy the cookie.
Login button click code.
raju vrPosted Oct 11, 2017, 6:45 AM
How to implement if we disable cookies
Sohaib AhmedPosted Nov 23, 2015, 3:58 AM
How to make sure that we have entered a unique KeyName for Cookies? What if some other website saved the cookies with the same KeyName?
Brijbhushan Kumar PatelPosted Apr 11, 2013, 9:21 AM
good article.
Ashok LuhacheditedPosted Apr 4, 2013, 1:12 AMEdited Apr 4, 2013, 1:14 AM
rememberMe checkbox checked=true property not set to checked this is my codeif (Request.Cookies["Remember"] != null){TextBox txtUserName = (TextBox)LoginUser.FindControl("UserName");TextBox txtPassword = (TextBox)LoginUser.FindControl("Password");CheckBox ChkRemember = (CheckBox)LoginUser.FindControl("RememberMe");HttpCookie cookieRemember = Request.Cookies.Get("Remember");txtUserName.Text = cookieRemember.Values["Email"];txtPassword.Attributes.Add("value", cookieRemember.Values["Password"]); ChkRemember.Checked = true;} but after pageload there are value in both textbox but checkbox not checked true
Mahesh AllePosted Mar 12, 2013, 7:05 AM
Its a good article.
Sharad GuptaPosted Mar 7, 2013, 5:07 AM
nice article