Reputation: 287
I am new to C# Programming.
I had drag a login control into my website. But the "Remember me" seem not to be working if i didn't add any codes in.
Anyone can teach me how to implement the "remember me" in c#?
I want it to be when the user revisit the website, he/she type onto the username textbox, the password will be retrieved from the database and display on the password textbox and at the same time the rememberme checked box will be check.
I had been researching this for the code for was for days, but was not fruitful.
Anyone can give me a tutorial on this?
Desperately wanting to know how it works.
Hope to get reply soon.
Thank.
Upvotes: 0
Views: 5891
Reputation: 25091
Anyone can teach me how to implement the "remember me" in c#?
From MSDN:
If you want the control to display a "Remember me next time" check box, set the DisplayRememberMe
property to true
. If a user selects the "Remember me next time check box" when he or she logs in, the authentication token will be stored in a persistent cookie in the browser.
If you want the "Remember me next time" check box to be selected by default, set the RememberMeSet
property to true
.
If you want the authentication token to be stored in a persistent cookie without giving the user the option to clear the "Remember me next time" check box, set the RememberMeSet
property to true
and set the DisplayRememberMe
property to false
. This is not recommended for sites that can be accessed from public computers that serve multiple users, as a user's persistent authentication token could be used by an unwanted user.
I want it to be when the user revisit the website, he/she type onto the username textbox, the password will be retrieved from the database and display on the password textbox and at the same time the rememberme checked box will be check.
That's not how the "Remember Me" checkbox works. All the checkbox does is store an authentication ticket in a cookie in the browser. When the user revisits the site, there is no prompt for login as the authentication ticket already exists, so the user is automatically logged in.
It's conceivable that you could modify the login ASCX with some JavaScript to do exactly what you want, but in good conscience I cannot recommend you do that as it would render your site incredibly insecure.
Upvotes: 6
Reputation: 7539
The way you think the "remember me" check box works is incorrect. When a user selects Remember Me, if they successfully login, their user name and password are stored in a session cookie until the cookie expires. Nothing is retrieved from the database at this time - that is very insecure!
EDIT ** May I suggest watching a video on the built-in ASP.Net Login server controls. I think that you should use these while you are getting a handle on ASP.Net & C# programming.
Upvotes: 4