Go Asp. NET inside easy to remember user name and password

Source: Internet
Author: User

 Using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 using System.Data;     8 9 public partial class _default:system.web.ui.page {protected void Page_Load (object sender, EventArgs e) 12 {if (!              IsPostBack) 14 {15//Read saved COOKIE information HttpCookie cookies = request.cookies["User_cookie"];17 if (cookie = null) 18 {19//If the cookie is not empty, the user name and password inside the cookie are read out and assigned to the foreground text box.  This.txtUserName.Text = cookies["UserName"];21 this.txtPassword.Attributes.Add ("value", cookies["UserPassword"]); 22//The option to remember the password is still selected here. this.ckbRememberLogin.Checked = true;24}25}26}27-protected void ASPXB  Utton1_click (object sender, EventArgs e) {string UserName = txtusername.text;31 string Password =  Txtpassword.text;32       This usertable is the user information that the data layer obtains. The DataTable usertable = new Usermanager (). Getusertable (UserName);//usertable.rows.count>0 Note that there is a corresponding record in the database and you can continue execution. if (UserTable.Rows.Count > 0) 36 {37//If the password obtained from the cookie is consistent with the password in the database, the login is successful. F (usertable.rows[0]["Password"). ToString () = = Password) (HttpCookie cookie = new HttpCookie ("User_cookie") if (this.ckbRememberLogin.Checked) 42 {43//All verification information is detected, if the user chooses to remember the password , the user name and password are written to the cookie and stored. Cookies. Values.add ("UserName", This.txtUserName.Text.Trim ()); Values.add ("UserPassword", This.txtPassword.Text.Trim ()); 46//This is the setting of the cookie expiration time, here set one weeks time, after one weeks after the state security Automatically emptied. Cookies.                 Expires = System.DateTime.Now.AddDays (7.0); HttpContext.Current.Response.Cookies.Add (cookie); 49     }50            else51 {cookie["User_cookie"]! = null) 53 {54 If the user does not choose to remember the password, the information in the cookie is immediately set and the setting status remains immediately expired. response.cookies["User_cookie"]. Expires = datetime.now;56}57}58//scriptmanager.registerclientscript Block (this, this.) GetType (), "Script", "<script>alert ('" + ex.         Message + "') </script>", false); Response.Redirect ("Default.aspx"); 61 62}63 }64}65}

(GO) ASP. NET inside easy to remember user name and password

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.