12asp.net============= User Login System

Source: Internet
Author: User

1   Public stringerrormsg {Get;Set; }2         protected voidPage_Load (Objectsender, EventArgs e)3         {4             if(IsPostBack)5             {6                 //Determine If the code is correct before judging the user name and password. 7                 if(Checkvalidatecode ())8                 {9Checkuserinfo ();//Verifying the user name passwordTen                 } One                 Else A                 { -ErrorMsg ="Verification Code Error !"; -                 } the             } -             Else -             { -                 //determine if there is a value in the cookie. If there is a value and the value is correct, then the jump does not require the user to enter the user name and password. If the cookie has no value, or if the value is wrong, continue to render the login form and let the user enter the user name password to log in.  + checkcookieinfo (); -  +             } A         } at  -         /// <summary> -         ///verifying the information of a cookie -         /// </summary> -         Private voidCheckcookieinfo () -         { in             if(request.cookies["CP1"] !=NULL&& request.cookies["CP2"] !=NULL) -             { to                 stringUserName = request.cookies["CP1"]. Value; +                 stringUserpwd = request.cookies["app"]. Value; -Bll. Userinfoservice Userinfoservice =NewBLL. Userinfoservice (); theUserInfo userinfo=Userinfoservice.getuserinfomodel (userName); *                 if(UserInfo! =NULL)//depending on the user name stored in the cookie, if not NULL, the user name stored in the cookie is correct.  $                 {Panax Notoginseng                     //determine if the password stored in the user's database is consistent with the password stored in the cookie. Note: When registering, be sure to encrypt the password entered by the user after it is stored in the database. If the user registration password has been two times MD5 operation, then the direct comparison here is OK.  -                     if(Userpwd = =Common.WebCommon.GetMd5String (Common.WebCommon.GetMd5String (Userinfo.userpass))) the                     { +session["UserInfo"] =UserInfo; AResponse.Redirect ("userlist.aspx"); the                     } +  -                 } $                 //If there is a value in the cookie, but the user name or password stored by the cookie is incorrect, indicating that the user name and password have been tampered with, then only the login page will continue to appear. Then there is no need for the cookie to exist.  $response.cookies["CP1"]. Expires = DateTime.Now.AddDays (-1); -response.cookies["app"]. Expires = DateTime.Now.AddDays (-1); -             } the         } - Wuyi         /// <summary> the         ///Verify that the user's user name and password are correct -         /// </summary> Wu         Private voidCheckuserinfo () -         { About             stringUserName = request.form["Txtclientid"]; $             stringUserpwd = request.form["Txtpassword"]; -Bll. Userinfoservice Userinfoservice =NewBLL. Userinfoservice (); -             stringmsg =string. Empty; -UserInfo userinfo=NULL; A             if(Userinfoservice.checkloginuserinfo (UserName, Userpwd, outMsg outuserInfo)) +             { the                 //determine if the user has selected automatic login -                 if(!string. IsNullOrEmpty (request.form["Autologin"]))//If there are multiple checkboxes in the form, only the selected value is submitted to the server $                 { theHttpCookie Cookie1 =NewHttpCookie ("CP1", userName); theHttpCookie Cookie2 =NewHttpCookie ("app", Common.WebCommon.GetMd5String (Common.WebCommon.GetMd5String (USERPWD))); theCookie1. Expires = DateTime.Now.AddDays (3); theCookie2. Expires = DateTime.Now.AddDays (3); - Response.Cookies.Add (cookie1); in Response.Cookies.Add (cookie2); the                 } the  About                 //if the above conditions are true, the user is entered with the correct user name and password. thesession["UserInfo"] =UserInfo; the                  theResponse.Redirect ("userlist.aspx"); +             } -             Else the             {BayiErrorMsg =msg; the             } the         } -  -         #regionVerification code to verify the         Private BOOLCheckvalidatecode () the         { the             //Note: The session is used to determine if the value is empty. the             BOOLIssucess =false; -             if(session["Code"] !=NULL) the             { the                 stringTxtcode = request.form["Txtcode"]; the                 stringSyscode = session["Code"]. ToString ();94                 if(Syscode.equals (Txtcode, stringcomparison.invariantcultureignorecase)) the                 { thesession["Code"] =NULL; theIssucess =true;98                 } About             } -             returnissucess;101         }102 103         #endregion104}
1Context. Response.ContentType ="Text/plain";2Common.validatecode Validatecode =NewCommon.validatecode ();3             stringCode=validatecode.createvalidatecode (4);4Context. session["Code"] = code;//Note: Using the session in a generic handler must implement the System.Web.SessionState.IRequiresSessionState interface.5Validatecode.createvalidategraphic (code, context);

12asp.net============= User Login System

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.