Asp.net uses cookies to save user passwords for Automatic Login
In this article, we will learn how to use cookies to save the user's account and password in asp.net for automatic logon. We emphasize that it is insecure to store cookies on the client. We recommend that you use md5 encryption to save them.
In asp.net, use cookies to save the account password and log on automatically ......
Create cookie
// Write the Cookie to the client
HttpCookie hcUserName1 = new HttpCookie ("uname"); // create a cookie named uname
HcUserName1.Expires = DateTime. Now. AddDays (7); // set the cookie Validity Period
HcUserName1.Value = uname; // assign a value to the cookie (that is, the account or password you want to save)
HttpContext. Current. Response. Cookies. Add (hcUserName1); // submit the cookie
Extract cookie
If (HttpContext. Current. Request. Cookies ["uname"]! = Null) // if this uname cookie is not empty
String uname = HttpContext. Current. Request. Cookies ["uname"]. Value. ToString (); // extract cookie
Destroy cookie
// Set the cookie time to-1, that is, the cookie expires and is destroyed.
HttpContext. Current. Response. Cookies ["uname"]. Expires = DateTime. Now. AddSeconds (-1 );