/// </summary> /// <param name="userName"></param> /// <param name="passWord"></param> /// <returns></returns> public bool Login(String userName, String passWord) { bool succ = false; JTable tab1 = new JTable(TableName); List <SearchField> condition = new List <SearchField>(); condition.Add(new SearchField("UserName", userName)); DataSet ds1 = tab1.SearchData(condition, 1, "*"); if (ds1 != null && ds1.Tables[0].Rows.Count > 0) { DataRow dr1 = ds1.Tables[0].Rows[0]; if (JString.MD5(passWord) == dr1["password"].ToString() || passWord == dr1["password"].ToString()) { succ = true; JCookie.SetCookieValue("CurrentLogin", userName); if (dr1["isAdmin"].ToString().Trim() == "1") { HttpContext.Current.Session["isAdmin"] = true; } else { HttpContext.Current.Session["isAdmin"] = false; } dr1["LastLogin"] = DateTime.Now.ToString(); if (passWord == dr1["password"].ToString()) { dr1["password"] = JString.MD5(passWord); } tab1.Update(ds1.Tables[0]); } } ds1.Dispose(); tab1.Close(); return(succ); }
//submit login void but1_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(this.username.Value) == false) { if (String.IsNullOrEmpty(Request.Form["password"]) == false) { JUserBU bu1 = new JUserBU(); String userid = String.Empty; String departnum = String.Empty; int succ = bu1.Login(this.username.Value, Request.Form["password"], ref userid, ref departnum); if (succ == 0) { JAjax.AlertAndFocusControl("错误:用户名不存在!", this.username.ClientID); } else if (succ == 1) { JAjax.AlertAndFocusControl("错误:登录密码不正确!", "password"); } else if (succ == 2) { JAjax.AlertAndFocusControl("错误:用户名已停用,请联系管理员!", "password"); } else { //设置用户的登录 WebFrame.FrameLib.Login(userid); JCookie.SetCookieValue("login_userid", this.username.Value); JCookie.SetCookieValue("departnum", departnum); if (this.remember.Checked) { JCookie.SetCookieValue("login_password", Request.Form["password"]); JCookie.SetCookieValue("login_remember", "true"); } else { JCookie.SetCookieValue("login_password", ""); JCookie.SetCookieValue("login_remember", ""); } //设置登录后转向的URL String toUrl = "/SysManager/ManagerIndex.aspx"; if (String.IsNullOrEmpty(toUrl) == false) { Response.Redirect(toUrl, true); } } } else { JAjax.AlertAndFocusControl("错误:请输入登录的密码!", "password"); } } else { JAjax.AlertAndFocusControl("错误:请输入登录的用户名!", this.username.ClientID); } }