1. Login Code
/// <summary> ///Login/// </summary> /// <param name= "Userno" ></param> /// <param name= "password" ></param> /// <param name= "Persistcookie" ></param> /// <returns></returns> Public Statickeyvaluepair<BOOL,string> Login (stringUserno,stringPasswordBOOLPersistcookie =false) { if(HttpContext.Current = =NULL)return Newkeyvaluepair<BOOL,string> (false,"Request Exception!"); Password= Com.encrypt (password, key);//The password was encrypted two times, this is the first time//this way, you need to verify that the account password is correct, and then write the cookieUser su=GetUser (Userno); httpcontext.current.session["CurrentUser"] =su; //If you tick remember me, write a cookie if(Persistcookie) {stringEuser = Com.encrypt ("User", key); stringEuserno = Com.encrypt ("Userno", key); stringEpassword = Com.encrypt ("Password", key); stringENo =Com.encrypt (Userno, key); stringePw = com.encrypt (password, key);//Password re-encrypted onceHttpCookie Cookie =Httpcontext.current.request.cookies[euser]; if(Cookie = =NULL|| !Cookie.values[euserno]. Equals (ENo)) {Cookie=NewHttpCookie (Euser); COOKIE.VALUES.ADD (Euserno, eNo);//write an account to a cookieCOOKIE.VALUES.ADD (Epassword, ePw);//write password to cookie ... The keys to these two cookies are also encryptedCookie.expires = DateTime.Now.AddDays (365); HTTPCONTEXT.CURRENT.RESPONSE.COOKIES.ADD (Cookie); } } return Newkeyvaluepair<BOOL,string> (true,""); }
2. Exit code
is to get the cookie that was written before it, and then set its effective time
/// <summary> ///Log Out/// </summary> /// <returns></returns> Public Statickeyvaluepair<BOOL,string>Logout () {if(HttpContext.Current = =NULL)return Newkeyvaluepair<BOOL,string> (false,"Request Exception!"); httpcontext.current.session["CurrentUser"] =NULL; httpcontext.current.session["Authenticated"] =NULL; stringEuser = Com.encrypt ("User", key); stringEuserno = Com.encrypt ("Userno", key); stringEpassword = Com.encrypt ("Password", key); HttpCookie Cookies=Httpcontext.current.request.cookies[euser]; if(Cookie! =NULL) {Cookie=NewHttpCookie (Euser); Cookie.expires= DateTime.Now.AddDays (-1); HTTPCONTEXT.CURRENT.RESPONSE.COOKIES.ADD (Cookie); } return Newkeyvaluepair<BOOL,string> (true,""); }
Login Exit code