Remember me functionality can be implemented in login page to save the user details. This can be implemented with the help of cookies. Cookies will stored in browser.
Here's what you need to do:
if (chkRememberPass.Checked == true)
{
Response.Cookies["UserName"].Value = txtUName.Text;
Response.Cookies["PWD"].Value = txtPWD.Text;
Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(2);
Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(2);
}
else
{
Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(-1);
Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(-1);
}
Paste the following code snippet in page load
if (!IsPostBack)
{
if (Request.Cookies["UserName"] != null)
txtUName.Text= Request.Cookies["UName"].Value;
if (Request.Cookies["PWD"] != null)
txtPWD.Text.Attributes.Add("value", Request.Cookies["PWD"].Value);
if (Request.Cookies["UserName"] != null && Request.Cookies["PWD"] != null)
chkRememberPassword.Checked = true;
}
Normally whenever the user closes the site, his authentication cookie (session id) expires as per the set rules. So when user comes after some time and opens the page he has to login again. Thus to implement remember me, you need to ensure that authentication
cookie does not expire unless user clicks on logout button. Set the expires property of auth cookie to some future date.
iam using this code in the company's web site check it
in login page in pageload event do the following
If Request.Browser.Cookies Then
If Request.Cookies("UserName") IsNot Nothing Then
txtEmailID.Text = Request.Cookies("UserName").Value.ToString()
End If
If Request.Cookies("PassWord") IsNot Nothing Then
txtPassword.Text = Request.Cookies("PassWord").Value.ToString()
flag = LoginDirectly(txtEmailID.Text, txtPassword.Text) 'function to check login
If flag Then
Response.Redirect("Default.aspx")
Else
lblLoginMsg.Text ="Invalid EmailID or password"
txtPassword.Text = ""
End If
End If
End If
and now in button login do the follwoing
Response.Cookies("UserName").Expires = DateTime.Now.AddDays(30)
Response.Cookies("UserName").Value = txtEmailID.Text
End If
If chkRemMe.Checked Then
Response.Cookies("PassWord").Expires = DateTime.Now.AddDays(30)
Response.Cookies("PassWord").Value = txtPassword.Text
End If
and in logout button do the following
If Request.Cookies("PassWordC") IsNot Nothing Then
Response.Cookies("PassWordC").Expires = DateTime.Now.AddDays(-30)
End If
this will delete only the password cookie and will keep the user name or emialID
Please "Mark as Answer" if this post helps.Thank You :)
How can i use Remember Id and password in login section in asp.net
<asp:Login ID="Login1" runat="server" >
<LayoutTemplate>
<asp:Label ID="lblLoginEmail" CssClass="Label" runat="server" Text="Email"></asp:Label>
<asp:TextBox ID="UserName" CssClass="TextBox" runat="server"></asp:TextBox>
<asp:Label ID="lblLoginPass" CssClass="Label" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="Password" CssClass="TextBox" TextMode="Password" runat="server"></asp:TextBox>
<asp:Label ID="lblRememberMe" runat="server" Text="Keep me logged in" ></asp:Label>
<asp:CheckBox id="ChkRememberMe" runat="server" CssClass="CheckRememberMe" />
<asp:Button ID="Login" CommandName="Login" ValidationGroup="LoginValid" CssClass="Label"
runat="server" Text="Login"></asp:Button>
</LayoutTemplate>
</asp:Login>
vb.net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'To reterive Username n password from cookies when page loads 1st time
If Not IsPostBack Then
If Request.Cookies("myCookie") IsNot Nothing Then
Dim cookie As HttpCookie = Request.Cookies.[Get]("myCookie")
CType(Login1.FindControl("ChkRememberMe"), CheckBox).Checked = Session("RememberME")
Dim RememberMeChk As Boolean = Session("RememberME")
If RememberMeChk = True Then
Debug.WriteLine("password")
CType(Login1.FindControl("UserName"), TextBox).Text = cookie.Values("USR")
Dim pass As TextBox = DirectCast(Login1.FindControl("Password"), TextBox)
pass.Attributes.Add("value", Request.Cookies("myCookie")("PWD1"))
Else
Debug.WriteLine("username")
CType(Login1.FindControl("UserName"), TextBox).Text = cookie.Values("USR")
End If
End If
' Note this
Response.Cache.SetNoStore()
End If
'to save username n password in cookies
If IsPostBack Then on postback
Dim checkME As Boolean = CType(Login1.FindControl("ChkRememberMe"), CheckBox).Checked
Session("RememberME") = checkME
If checkME = True Then
Dim myCookie As New HttpCookie("myCookie")
Debug.WriteLine("Checkbox is checked")
'Response.Cookies.Remove("myCookie");
Response.Cookies.Add(myCookie)
Dim CUserName As String = CType(Login1.FindControl("UserName"), TextBox).Text
Dim CPassword As String = CType(Login1.FindControl("Password"), TextBox).Text
myCookie.Values.Add("USR", CUserName)
myCookie.Values.Add("PWD1", CPassword)
Dim dtExpiry As DateTime = DateTime.Now.AddMonths(2)
Response.Cookies("myCookie").Expires = dtExpiry
Else
Debug.WriteLine("cookie expires")
Response.Cookies("USR").Expires = DateTime.Now.AddMonths(-1)
Response.Cookies("PWD1").Expires = DateTime.Now.AddMonths(-1)
End If
End If
End Sub
Smadhu
Member
512 Points
1000 Posts
how can i do Remember me on login section
May 07, 2012 05:23 AM|LINK
is it possible to give option like checkbox for remember me................if user select dat checkbox ...........computer will remember the
id n password as in yahoo or facebook.............how to do dat in asp.net
PLz do help
thnx
ZeeshanAnsar...
Participant
878 Points
264 Posts
Re: how can i do Remember me on login section
May 07, 2012 05:29 AM|LINK
see below solved thread.
http://forums.asp.net/t/1303629.aspx
Please 'Mark as Answer' if this post helps you.
nijhawan.sau...
All-Star
16460 Points
3178 Posts
Re: how can i do Remember me on login section
May 07, 2012 05:30 AM|LINK
Remember me functionality can be implemented in login page to save the user details. This can be implemented with the help of cookies. Cookies will stored in browser.
Here's what you need to do:
if (chkRememberPass.Checked == true) { Response.Cookies["UserName"].Value = txtUName.Text; Response.Cookies["PWD"].Value = txtPWD.Text; Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(2); Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(2); } else { Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(-1); Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(-1); } Paste the following code snippet in page load if (!IsPostBack) { if (Request.Cookies["UserName"] != null) txtUName.Text= Request.Cookies["UName"].Value; if (Request.Cookies["PWD"] != null) txtPWD.Text.Attributes.Add("value", Request.Cookies["PWD"].Value); if (Request.Cookies["UserName"] != null && Request.Cookies["PWD"] != null) chkRememberPassword.Checked = true; }Ruchira
All-Star
44413 Points
7197 Posts
MVP
Re: how can i do Remember me on login section
May 07, 2012 06:18 AM|LINK
Hello,
Check the below link
http://stackoverflow.com/questions/2100449/rememberme-option-in-an-asp-net-web-application
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.jigarbjpatel
Member
454 Points
88 Posts
Re: how can i do Remember me on login section
May 07, 2012 06:20 AM|LINK
Normally whenever the user closes the site, his authentication cookie (session id) expires as per the set rules. So when user comes after some time and opens the page he has to login again. Thus to implement remember me, you need to ensure that authentication cookie does not expire unless user clicks on logout button. Set the expires property of auth cookie to some future date.
nbsamurai
Member
608 Points
223 Posts
Re: how can i do Remember me on login section
May 07, 2012 06:43 AM|LINK
For ASP.NET :
When using Forms Authentication, pass
as a second boolean argument to RedirectFromLoginPage or use cookiesFor MVC :
http://stackoverflow.com/questions/5619791/implementing-remember-me-feature-in-asp-net-mvc
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: how can i do Remember me on login section
May 07, 2012 06:53 AM|LINK
iam using this code in the company's web site check it
in login page in pageload event do the following
If Request.Browser.Cookies Then If Request.Cookies("UserName") IsNot Nothing Then txtEmailID.Text = Request.Cookies("UserName").Value.ToString() End If If Request.Cookies("PassWord") IsNot Nothing Then txtPassword.Text = Request.Cookies("PassWord").Value.ToString() flag = LoginDirectly(txtEmailID.Text, txtPassword.Text) 'function to check login If flag Then Response.Redirect("Default.aspx") Else lblLoginMsg.Text ="Invalid EmailID or password" txtPassword.Text = "" End If End If End Ifand now in button login do the follwoing
Response.Cookies("UserName").Expires = DateTime.Now.AddDays(30) Response.Cookies("UserName").Value = txtEmailID.Text End If If chkRemMe.Checked Then Response.Cookies("PassWord").Expires = DateTime.Now.AddDays(30) Response.Cookies("PassWord").Value = txtPassword.Text End Ifand in logout button do the following
If Request.Cookies("PassWordC") IsNot Nothing Then Response.Cookies("PassWordC").Expires = DateTime.Now.AddDays(-30) End If this will delete only the password cookie and will keep the user name or emialIDsriramabi
Contributor
4351 Points
1277 Posts
Re: how can i do Remember me on login section
May 07, 2012 07:45 AM|LINK
Hai
are you use ligin control..
try this
<asp:CheckBox ID="RememberMe" runat="server" />
<asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe"
Width="500px">Keep me logged in</asp:Label>
thank u
hans_v
All-Star
35998 Points
6551 Posts
Re: how can i do Remember me on login section
May 07, 2012 07:55 AM|LINK
Also, Do not forget to increase the TimeOut value, because it defaults to 30 (minutes). And make sure you add a machine Key to your web.config
http://aspnetresources.com/tools/machineKey
Smadhu
Member
512 Points
1000 Posts
Re: how can i do Remember me on login section
May 07, 2012 08:17 AM|LINK
How can i use Remember Id and password in login section in asp.net <asp:Login ID="Login1" runat="server" > <LayoutTemplate> <asp:Label ID="lblLoginEmail" CssClass="Label" runat="server" Text="Email"></asp:Label> <asp:TextBox ID="UserName" CssClass="TextBox" runat="server"></asp:TextBox> <asp:Label ID="lblLoginPass" CssClass="Label" runat="server" Text="Password"></asp:Label> <asp:TextBox ID="Password" CssClass="TextBox" TextMode="Password" runat="server"></asp:TextBox> <asp:Label ID="lblRememberMe" runat="server" Text="Keep me logged in" ></asp:Label> <asp:CheckBox id="ChkRememberMe" runat="server" CssClass="CheckRememberMe" /> <asp:Button ID="Login" CommandName="Login" ValidationGroup="LoginValid" CssClass="Label" runat="server" Text="Login"></asp:Button> </LayoutTemplate> </asp:Login> vb.net Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'To reterive Username n password from cookies when page loads 1st time If Not IsPostBack Then If Request.Cookies("myCookie") IsNot Nothing Then Dim cookie As HttpCookie = Request.Cookies.[Get]("myCookie") CType(Login1.FindControl("ChkRememberMe"), CheckBox).Checked = Session("RememberME") Dim RememberMeChk As Boolean = Session("RememberME") If RememberMeChk = True Then Debug.WriteLine("password") CType(Login1.FindControl("UserName"), TextBox).Text = cookie.Values("USR") Dim pass As TextBox = DirectCast(Login1.FindControl("Password"), TextBox) pass.Attributes.Add("value", Request.Cookies("myCookie")("PWD1")) Else Debug.WriteLine("username") CType(Login1.FindControl("UserName"), TextBox).Text = cookie.Values("USR") End If End If ' Note this Response.Cache.SetNoStore() End If 'to save username n password in cookies If IsPostBack Then on postback Dim checkME As Boolean = CType(Login1.FindControl("ChkRememberMe"), CheckBox).Checked Session("RememberME") = checkME If checkME = True Then Dim myCookie As New HttpCookie("myCookie") Debug.WriteLine("Checkbox is checked") 'Response.Cookies.Remove("myCookie"); Response.Cookies.Add(myCookie) Dim CUserName As String = CType(Login1.FindControl("UserName"), TextBox).Text Dim CPassword As String = CType(Login1.FindControl("Password"), TextBox).Text myCookie.Values.Add("USR", CUserName) myCookie.Values.Add("PWD1", CPassword) Dim dtExpiry As DateTime = DateTime.Now.AddMonths(2) Response.Cookies("myCookie").Expires = dtExpiry Else Debug.WriteLine("cookie expires") Response.Cookies("USR").Expires = DateTime.Now.AddMonths(-1) Response.Cookies("PWD1").Expires = DateTime.Now.AddMonths(-1) End If End If End Sub