views:

817

answers:

8

My client wants me to enable a "Remember Me" checkbox when the user logs in. I am encrypting and storing both the username and password in a cookie.

However, you cannot write to a textbox when it's in password mode.

I've seen this done numerous times, so how are they doing it?

thanks in advance!

+8  A: 

How about instead of inserting the text into the login form, you just bypass the form completely and check the contents of the cookie right at the login page? Less work for the user, and it'll make it a little more seamless.

Alex Fort
what you meant to say is automatic login right?
Gulzar
Correct. Check the cookie before you even present the login form.
Alex Fort
Can't do it, they don't want the user automatically logged in, they just want the usernamd/password field set.
ManiacPsycho
A: 

You can set the expiration of the cookie in 2 weeks to keep the user logged in. That's how ASP.NET authentication works with persistent authentication. Remember to update the expiration on every request.

Eduardo Campañó
+2  A: 
Page_Load( ...)
 {
    ... process cookie ...
    if (cookie is good) Response.Redirect("content.aspx");
 }

Just remember to close and dispose any database activity before redirecting.

chris
+1  A: 

They don't want the user to automatically be logged in they just want the usernamd and password field pre-filled in.

I know it's stupid and the same thing as keeping you logged in, but it's their request.

I've mentioned that it's not the best security practice but they don't care.

sites like myspace use it, wher eyou go to myspace.com and your usernamd and password are already filled in.

ManiacPsycho
Usually that sort of behavior is done by the web browser, not the website.
Dan Walker
+1  A: 

I don't recall any web page doing something like that as you described but I think it's the web browsers automatically filling passwords. I know this is not a good solution but what you can do might be, setting the text of o normal textbox with stars or something like that in a different login page if there is a cookie to authenticate the user. You don't need to use the password from the textbox to authenticate the user anyway.

hakan
+1  A: 

If your server-side code has access to their username and password from the cookie, then can't your page just populate the value attributes of the form fields like so:

<input type="text" name="username" value="<%=decryptedUsername%>" />
<input type="password" value="<%=decryptedPassword%>" />

Of course, this is pretty un-secure as you're echo-ing the users password back to them in plain-text (which is a big no-no). But as you say your client isn't that bothered about the security implications. If they are then SSL may help mitigate this risk.

spmason
A: 

Thatz quite straight forward, try using:

txtPass.Attributes["value"] = "123456"; (most probably on the page load event handler)

where txtPass is the id of the password textbox (in password mode). and the password u want displayed is 123456.

A: 

Is it possible for the text box to have the type changed? If so, can you make the text box normal and hidden, then put the password in there, then change the text box type to password type, then unhide it...

Guy