. Net Logon mode and. net Logon Mode
Ideas:
1. Check Logon:
Private string CheckLogin (HttpContext context) {Model. TUser model = (Model. TUser) context. session ["USERModel"]; if (model = null) {return "{\" msg \ ": \" 0 \ ", \" msgbox \": \ "currently exited \"} ";} else {return" {\ "msg \": \ "1 \", \ "msgbox \": \ "currently logged on \"}";}}
2. Click to log on:
Private string Login (HttpContext context) {BLL. TUser _ blluser = new BLL. TUser (); string loginname = context. request. params ["loginname"]; string password = context. request. params ["password"]; string issave = context. request. params ["issave"]; // whether to save the password Model. TUser model_user = _ blluser. getModel ("UserLogin = '" + loginname + "'"); bool isSuccess = false; string cookiesPassword = ""; // determine whether Cookies exist if (HttpContext. Current. Request. Cookies ["password"]! = Null) {cookiesPassword = HttpContext. current. request. cookies ["password"]. value; if (password = cookiesPassword) // enter the same password as the cookie {// isSuccess = true ;}} // determine whether the entered password matches the database if (! IsSuccess) {if (password = model_user.PassWord) {// isSuccess = true;} else {// logon Failure isSuccess = false;} if (isSuccess) {context. session ["USERModel"] = model_user;} else {// The Logon Failed password is incorrect. return "{\" msg \ ": \" 0 \ ", \" msgbox \": \ "Incorrect password \"} ";}// to save, write the cookie if (issave =" true ") {HttpCookie cookieLogin = new HttpCookie (" loginname "); cookieLogin. expires = DateTime. now. addDays (10); cookieLogin. value = model_user.UserLogin; HttpContext. current. response. cookies. add (cookieLogin); HttpCookie cookiePassword = new HttpCookie ("password"); cookiePassword. expires = DateTime. now. addDays (10); cookiePassword. value = password; HttpContext. current. response. cookies. add (cookiePassword);} else {// set cookie expiration, delete cookie HttpCookie cookieLogin = new HttpCookie ("loginname"); cookieLogin. expires = DateTime. now. addDays (-1); HttpContext. current. response. cookies. add (cookieLogin); HttpCookie cookiePassword = new HttpCookie ("password"); cookiePassword. expires = DateTime. now. addDays (-1); HttpContext. current. response. cookies. add (cookiePassword);} return "{\" msg \ ": \" 1 \ ", \" msgbox \ ": \" Logon successful \"}";}
3. When the page is refreshed, get the account name and password saved by the user and log on without logon.
Private string IsSaveUserLogin (HttpContext context) {// determine whether Cookies exist if (HttpContext. current. request. cookies ["loginname"] = null | HttpContext. current. request. cookies ["password"] = null) {return "{\" msg \ ":-1, \" msgbox \ ": \" account not saved \", \ "loginname \": \ "\", \ "password \": \ "\"} ";} else {string loginname = HttpContext. current. request. cookies ["loginname"]. value; string password = HttpContext. curre Nt. request. cookies ["password"]. value; // login-free CookieLogin (context, loginname, password); return "{\" msg \ ": 1, \" msgbox \ ": \" account saved \", \ "loginname \": \ "" + loginname + "\", \ "password \": \ "" + password + "\"}";}} private void CookieLogin (HttpContext context, string cookiesLoginname, string cookiesPassword) {Model. TUser model_user = new Model. TUser (); BLL. TUser _ blluser = new BLL. TUser (); bool isSuccess = False; // determine whether Cookies exist if (! String. IsNullOrEmpty (cookiesLoginname )&&! String. isNullOrEmpty (cookiesPassword) {model_user = _ blluser. getModel ("UserLogin = '" + cookiesLoginname + "'"); if (model_user.PassWord = cookiesPassword) /// the password for the database and Cookies is the same {// isSuccess = true;} if (isSuccess) {// context for successful login. session ["USERModel"] = model_user;} else {// logon Failure password incorrect // return "{\" msg \ ": \" 0 \", \ "msgbox \": \ "Incorrect password \"}";}}
4. log out and clear cookies and sessions.
Private string UserExit (HttpContext context) {// clear cookie // HttpContext. current. request. cookies. clear (); // invalid HttpCookie cookieLogin = new HttpCookie ("loginname"); cookieLogin. expires = DateTime. now. addDays (-1); HttpContext. current. response. cookies. add (cookieLogin); HttpCookie cookiePassword = new HttpCookie ("password"); cookiePassword. expires = DateTime. now. addDays (-1); HttpContext. current. response. cookies. add (cookiePassword); context. session ["USERModel"] = null; context. session. clear (); return "";}