Asp.net uses cookies to save user passwords for Automatic Login

Source: Internet
Author: User

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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.