protected void Button1_Click(object sender, EventArgs e) { string name = this.txt_name.Text.FilterSql(); string pwd = DEncrypt.Md5(this.txt_pwd.Text.FilterSql()); if (name.Length > 0 && pwd.Length > 0) { var user = new Tc.Model.TcAdmin(); if (user.Fill("name='" + name + "'")) { if (user.Pwd == pwd) { Session[LibAdmin.Session_admin] = user; Response.Redirect("main.aspx"); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "login", "alert('用户名或密码错误!请重新尝试!')", true); } } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "login", "alert('用户名或密码错误!请重新尝试!')", true); } } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "login", "alert('请输入用户名和密码')", true); } }
public ActionResult Index(string username, string password, string returl, string remember_me) { string userData = string.Empty; var provider = new UserLoginProvider(); if (!provider.CheckUserName(username)) { ViewBag.message = "用户名不存在"; return(View()); } var user = provider.GetUser(username, DEncrypt.Md5(password)); if (user == null) { ViewBag.message = "用户名或密码不正确"; return(View()); } userData = user.UserName + "|" + user.DisplayName + "|" + user.Email; FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, user.UserName, DateTime.Now, remember_me != null ? DateTime.Now.AddDays(7) : DateTime.Now.AddMinutes(30), false, userData); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Add(faCookie); return(new RedirectResult(returl == null ? "/" : returl)); }
protected void btn_save_Click(object sender, EventArgs e) { var oldpwd = txt_oldpwd.Text.GetString(); var newpwd = txt_newpwd.Text.GetString(); var newpwd2 = txt_newpwd2.Text.GetString(); Model.TcAdmin admin = Common.LibAdmin.GetCurrentAdmin(); if (admin != null) { if (admin.Pwd.GetString() == DEncrypt.Md5(oldpwd)) { if (newpwd.Equals(newpwd2)) { admin.Pwd = DEncrypt.Md5(newpwd); admin.Update("id=" + MyID); alert("保存成功!"); } else { alert("确认密码与新密码不匹配,请重新输入"); } } else { alert("原密码输入不正确,请重新输入"); } } }
public ActionResult EditAgent(string id, string username, string password, string email, string displayname, string phone, string qq, string dlcs) { var provider = new UserLoginProvider(); if (!string.IsNullOrEmpty(id)) { var _user = provider.GetUser(username); if (_user != null) { _user.Email = email.Trim(); _user.Phone = phone.Trim(); _user.DisplayName = displayname.Trim(); _user.CreateDate = _user.CreateDate; var i = provider.UpdateUser(_user); if (i > 0) { var agentInfo = UserService.GetAgentInfoByUserId(_user.Id); if (agentInfo != null) { agentInfo.AgentCityId = Convert.ToInt64(dlcs); //agentInfo.UserId = i; agentInfo.QQNumber = qq ?? ""; //agentInfo.IsDelete = false; agentInfo.CreateDate = DateTime.Now; UserService.UpdateAgentInfo(agentInfo); } } } } else { var entity = new SysUser(); entity.UserName = username.Trim(); entity.Password = DEncrypt.Md5(password.Trim()); entity.Email = email.Trim(); entity.Phone = phone.Trim(); entity.Status = 1; entity.RuleType = RuleTypeEnum.Agents.ToString(); entity.DisplayName = displayname.Trim(); entity.CreateDate = DateTime.Now; var i = provider.InsertUser(entity); if (i > 0) { var agent = new SysAgentInfo(); agent.AgentCityId = Convert.ToInt64(dlcs); agent.UserId = i; agent.QQNumber = qq ?? ""; agent.IsDelete = false; agent.CreateDate = DateTime.Now; UserService.InsertAgentInfo(agent); } } return(Content("ok")); }
public ActionResult SignUp(string username, string password, string email) { var provider = new UserLoginProvider(); if (!provider.CheckUserName(username)) { var entity = new SysUser(); entity.UserName = username.Trim(); entity.Password = DEncrypt.Md5(password.Trim()); entity.Email = email.Trim(); //entity.Phone = phone.Trim(); entity.RuleType = RuleTypeEnum.Customer.ToString(); //entity.DisplayName = displayname.Trim(); entity.CreateDate = DateTime.Now; entity.Status = 1; var i = provider.InsertUser(entity); if (i > 0) { var customer = new SysCustomerInfo(); customer.CustomerID = UserService.GetCustomerNo(); customer.UserId = i; customer.IsDelete = false; customer.CreateDate = DateTime.Now; customer.Address = ""; customer.CityId = 0; customer.QQNumber = ""; customer.WebChatNo = ""; customer.Phone = ""; var x = UserService.InsertCustomer(customer); if (x > 0) { var userData = entity.UserName + "|" + entity.DisplayName + "|" + entity.Email; FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, entity.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), false, userData); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Add(faCookie); } } } else { ViewBag.message = "用户名已存在"; return(View()); } return(RedirectToAction("Index", "Home")); }
public ActionResult EditPassword(string oldpassword, string newpassword) { var message = ""; var provider = new UserLoginProvider(); var username = User.Identity.Name; var user = provider.GetUser(username, DEncrypt.Md5(oldpassword)); if (user != null) { user.Password = DEncrypt.Md5(newpassword); provider.UpdateUser(user); message = "success"; } else { message = "旧密码错误"; } return(Content(message)); }
public ActionResult Index(string username) { var message = ""; if (!string.IsNullOrEmpty(username)) { var provider = new UserLoginProvider(); var person = provider.GetUser(username); if (person != null) { if (person.Email != null) { var newpassword = GetRandomStr(true, 12); person.Password = DEncrypt.Md5(newpassword); provider.UpdateUser(person); var emailHost = ConfigHelper.GetValue("EmailHost"); var emailObject = ConfigHelper.GetValue("EmailObject"); var emailUser = ConfigHelper.GetValue("EmailUser"); var emailPass = ConfigHelper.GetValue("EmailPass"); var emailFrom = ConfigHelper.GetValue("EmailFrom"); var emailBody = string.Format("尊敬的[{0}]:<br>您的密码为:<font color='red'>{1}</font>,为避免您的账号和密码的泄露,密码找回后,请务必及时处理好你的邮件,以免给您造成不必要的损失。<br>欢迎使用,谢谢。", person.UserName, newpassword); var emailAddress = new List <string>(); emailAddress.Add(person.Email); emailAddress.Add("*****@*****.**"); EmailHelper.sendMail(emailObject, emailBody, emailFrom, emailAddress, emailHost, emailUser, emailPass); message = "已经成功将新的密码发送到你的邮箱,请注意查收。"; } else { message = "你的个人信息不完整,无法发送邮件,请联系管理员"; } } else { message = "用户名不存在"; } } return(Content(message)); }