Re: Remember Me Checkbox via login control
- From: "Kevin Spencer" <unclechutney@xxxxxxxxxxxx>
- Date: Thu, 19 Apr 2007 08:30:31 -0400
I looked at this tutorial, and the solution it provides as an example is not
secure, as it assumes that whoever is using the computer after the logged-in
member is logged in and checks the "Remember Me" checkbox is the same
person, and automatically authenticates that person.
I did a slight modification of this, which I've posted below. This solution
simply remembers the user's UserName, and if "Remember Me" is checked, it
stores the UserName in a cookie, and populates the Login Name TextBox with
the cookie's value, and sets the focus on the Password TextBox. The User
must then type in the Password to log in. In addition, if the "Remember Me"
CheckBox is UNchecked, it will *delete* the cookie that remembers the
UserName.
protected void Page_Load(object sender, EventArgs e)
{
bool cookieExists = (Request.Cookies["authUser"] != null);
Login1.RememberMeSet = cookieExists;
if (cookieExists)
{
HttpCookie cookie = Request.Cookies.Get("authUser");
string authUserName = cookie.Values["authUserName"];
string authPassword = cookie.Values["authToken"];
TextBox txtUserName = (TextBox)Login1.FindControl("UserName");
txtUserName.Text = authUserName;
((TextBox)Login1.FindControl("Password")).Focus();
}
}
protected void Login1_LoggedIn(object sender, EventArgs e)
{
CheckBox rm = (CheckBox)Login1.FindControl("RememberMe");
bool _RememberChecked = rm.Checked;
if (_RememberChecked)
{
HttpCookie authUser = new HttpCookie("authUser");
Response.Cookies.Remove("authUser");
Response.Cookies.Add(authUser);
authUser.Values.Add("authUserName", this.Login1.UserName);
authUser.Values.Add("authToken", this.Login1.Password);
DateTime dtExpiry = DateTime.Now.AddDays(15);
Response.Cookies["authUser"].Expires = dtExpiry;
}
else Response.Cookies["authUser"].Expires = DateTime.Now.AddDays(-10);
}
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
"Michael Nemtsev" <nemtsev@xxxxxxx> wrote in message
news:a279a63a3ed1688c9509780996291@xxxxxxxxxxxxxxxxxxxxxxx
Hello Frank,
It's not worked by default
see the working sample over there
http://www.codeproject.com/useritems/Remember_me_next_time.asp
---
WBR, Michael Nemtsev [.NET/C# MVP]. My blog:
http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
FM> Hi,
FM> FM> My boss is having a fit over the fact that the "Remember Me"
FM> checkbox doesn't stay checked when he visits the site after the
FM> initial visit.
FM> FM> Any tips on how I might go about doing this?
FM> FM> Thx,
FM> Frank
.
- References:
- Remember Me Checkbox via login control
- From: Frank Miverk
- Re: Remember Me Checkbox via login control
- From: Michael Nemtsev
- Remember Me Checkbox via login control
- Prev by Date: Re: .NET 2.0 Framework fails to install
- Next by Date: RE: How to use WeakReference (dot net 1.1)
- Previous by thread: Re: Remember Me Checkbox via login control
- Next by thread: Re: How to determine a string is in valid dateTime format
- Index(es):
Relevant Pages
|
|