asp.net Autologon Method by Saving User Password with cookie
- 2021-06-28 12:13:41
- OfStack
This article gives an example of how asp.net can use cookie to save user passwords for automatic login.Share it for your reference.Specific analysis is as follows:
cookie can save user's account password in asp.net to achieve automatic login function, but it needs to be emphasized that under 1, cookie is unsafe to save on the client, md5 encryption is recommended.
Below is an analysis of how cookie is created, extracted, and destroyed in asp.net:
Create cookie
// Write to Client Cookie
HttpCookie hcUserName1 = new HttpCookie("uname"); // Establish 1 Named uname Of cookie
hcUserName1.Expires = DateTime.Now.AddDays(7); // Set this cookie Effective time
hcUserName1.Value = uname; // to cookie Assignment (that is, the account or password you want to save)
HttpContext.Current.Response.Cookies.Add(hcUserName1); // Submit cookie
Extracting cookie
if (HttpContext.Current.Request.Cookies["uname"] != null) // If this uname cookie Not empty
string uname = HttpContext.Current.Request.Cookies["uname"].Value.ToString(); // extract cookie
Destroy cookie
// hold cookie Set time to -1 That is, cookie Expire, destroy
HttpContext.Current.Response.Cookies["uname"].Expires = DateTime.Now.AddSeconds(-1);
I hope that the description in this paper will be helpful to everyone's asp.net program design.