public void ProcessRequest(HttpContext context) { string userId = context.Request.Form["user[userId]"]; string oldPwd = context.Request.Form["user[old-pwd]"]; string newPwd1 = context.Request.Form["user[new-pwd-1]"]; string s = "{\"status\":\"error\"}"; bool b = false; MemberEntity memberEntity = MemberBll.Instance.GetModel(Convert.ToInt32(userId)); if (memberEntity != null) { if (memberEntity.Password == DEncryptUtils.Encrypt3DES(oldPwd)) { memberEntity.Password = DEncryptUtils.Encrypt3DES(newPwd1); b = MemberBll.Instance.Update(memberEntity); if (b) { s = "{\"status\":\"success\"}"; } } } context.Response.ContentType = "text/plain"; context.Response.Write(s); }
public void ProcessRequest(HttpContext context) { string code = context.Request.Form["user[token]"]; string pwd = context.Request.Form["user[pwd]"]; bool b = false; DataTable dt = MemberBll.Instance.GetList("code='" + code + "'").Tables[0]; MemberEntity memberEntity = MemberBll.Instance.GetModel(Convert.ToInt32(dt.Rows[0]["User_id"])); memberEntity.Password = DEncryptUtils.Encrypt3DES(pwd); memberEntity.Activation = "1"; b = MemberBll.Instance.Update(memberEntity); context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; context.Response.Write(b); }
public ActionResult Login(LoginViewModel loginViewModel) { if (TempData["VerificationCode"] == null || TempData["VerificationCode"].ToString() != loginViewModel.VerificationCode?.ToUpper()) { ModelState.AddModelError("VerificationCode", "验证码不正确"); return(View("Login", loginViewModel)); } var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { Member user = _memberService.Find(loginViewModel.UserName); if (user == null) { ModelState.AddModelError("UserName", "用户名不存在"); return(View("Login", loginViewModel)); } else if (user.Password == DEncryptUtils.Encrypt3DES(loginViewModel.Password)) { var identity = _memberService.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn( new AuthenticationProperties() { IsPersistent = loginViewModel.RememberMe }, identity); //return RedirectToAction("Index", "Start"); //return Json(new Dictionary<string, string>() { { "status", "success" }, { "message", "登录成功" } }); ViewBag.Message = "success"; return(View("Login", loginViewModel)); } else { ModelState.AddModelError("Password", "密码错误"); return(View("Login", loginViewModel)); } } ViewBag.Message = "error"; return(View("Login", loginViewModel)); //return Json(new Dictionary<string, string>() { { "status", "error" }, { "message", "错误请求" } }); }
public object UpdatePassword(string userId, string oldPwd, string newPwd) { MemberEntity memberEntity = MemberBll.Instance.GetModel(Convert.ToInt32(userId)); if (memberEntity != null) { if (memberEntity.Password == DEncryptUtils.Encrypt3DES(oldPwd)) { memberEntity.Password = DEncryptUtils.Encrypt3DES(newPwd); if (MemberBll.Instance.Update(memberEntity)) { return(new Dictionary <string, string>() { { "status", "200" }, { "message", "修改成功" } }); } else { return(new Dictionary <string, string>() { { "status", "400" }, { "message", "修改失败" } }); } } else { return(new Dictionary <string, string>() { { "status", "400" }, { "message", "原始密码错误" } }); } } else { return(new Dictionary <string, string>() { { "status", "400" }, { "message", "未找到用户" } }); } }
public ActionResult Password(PasswordViewModel model) { if (TempData["SMSCode"] == null || TempData["SMSCode"].ToString() != model.SMSCode.ToUpper()) { ModelState.AddModelError("SMSCode", "短信验证码不正确"); return(PartialView("_PartialPassword", model)); } if (ModelState.IsValid) { int uid = Com.Cos.Common.Public.GetLoginUid(); var user = _memberService.Find(uid); if (user.Password != DEncryptUtils.Encrypt3DES(model.OldPassword)) { ModelState.AddModelError("OldPassword", "密码错误"); return(PartialView("_PartialPassword", model)); } else { user.Password = DEncryptUtils.Encrypt3DES(model.Password); bool b = _memberService.Update(user); if (b) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return(Json(new Dictionary <string, string>() { { "status", "success" }, { "message", "修改成功" } })); } else { return(Json(new Dictionary <string, string>() { { "status", "error" }, { "message", "修改失败" } })); } } } return(PartialView("_PartialPassword", model)); }
/// <summary> /// 账号注册 /// </summary> /// <param name="nickname">昵称</param> /// <param name="acc">邮箱</param> /// <param name="pwd">密码(未加密)</param> /// <returns></returns> public static string Register(string nickname, string acc, string pwd) { string email, phone; if (RegexUtil.IsEmail(acc)) { email = acc; phone = ""; } else { phone = acc; email = ""; } MemberEntity memberEntity = new MemberEntity(); memberEntity.User_name = ""; memberEntity.Email = email; memberEntity.Password = DEncryptUtils.Encrypt3DES(pwd); memberEntity.Real_name = ""; memberEntity.nickname = nickname; memberEntity.Phone_mob = phone; memberEntity.Gender = memberEntity.Birthday = memberEntity.Phone_tel = memberEntity.Im_qq = memberEntity.Im_msn = memberEntity.In_skype = memberEntity.Im_yahoo = memberEntity.Im_aliww = memberEntity.Outer_id = memberEntity.Feed_config = ""; memberEntity.Portrait = "/Upload/Portrait/1.jpg"; memberEntity.Reg_time = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); memberEntity.Last_login = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); memberEntity.Last_ip = IpHelper.GetUserIp(); memberEntity.Logins = 0; memberEntity.Ugrade = 1; memberEntity.Status = 1; memberEntity.reward = 0; memberEntity.CNbi = 0; memberEntity.integral = 0; memberEntity.ardent = 0; memberEntity.Growth = 0; memberEntity.Describe = ""; memberEntity.Shenjia = 0; memberEntity.Bean = ""; memberEntity.code = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Guid.NewGuid().ToString(), "MD5"); memberEntity.Activation = "0"; if (RegexUtil.IsEmail(acc)) { if (SendRegisterMail(nickname, memberEntity.code, email)) { if (MemberBll.Instance.Add(memberEntity) > 0) { return("注册成功"); } else { return("账号信息保存失败"); } } else { return("邮件发生失败"); } } else { if (MemberBll.Instance.Add(memberEntity) > 0) { return("注册成功"); } else { return("账号信息保存失败"); } } }
public object LoginValidate(string acc, string pwd) { if (RegexUtil.IsEmail(acc)) { DataTable dt = MemberBll.Instance.GetList("Email='" + acc + "' AND Password='******'").Tables[0]; if (dt.Rows.Count > 0) { return(new Dictionary <string, string>() { { "status", "200" }, { "UserId", dt.Rows[0]["User_id"].ToString() } }); } else { return(new Dictionary <string, string>() { { "status", "400" }, { "message", "邮箱或密码不正确" } }); } } else { DataTable dt = MemberBll.Instance.GetList("Phone_mob='" + acc + "' AND Password='******'").Tables[0]; if (dt.Rows.Count > 0) { return(new Dictionary <string, string>() { { "status", "200" }, { "UserId", dt.Rows[0]["User_id"].ToString() } }); } else { return(new Dictionary <string, string>() { { "status", "400" }, { "message", "手机号或密码不正确" } }); } } }
/// <summary> /// 密码加密 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { textBox2.Text = DEncryptUtils.Encrypt3DES(textBox1.Text); }
public void ProcessRequest(HttpContext context) { string nickname = context.Request.Form["user[nickname]"]; string email = context.Request.Form["user[email]"]; string pwd = context.Request.Form["user[pwd]"]; string s = "{\"status\":\"error\"}"; bool b = false; DataTable dt = MemberBll.Instance.GetList("Email='" + email + "'").Tables[0]; if (dt.Rows.Count > 0) { s = "{\"status\":\"exist\"}"; return; } MemberEntity memberEntity = new MemberEntity(); memberEntity.User_name = ""; memberEntity.Email = email; memberEntity.Password = DEncryptUtils.Encrypt3DES(pwd); memberEntity.Real_name = ""; memberEntity.nickname = nickname; memberEntity.Gender = memberEntity.Birthday = memberEntity.Phone_tel = memberEntity.Phone_mob = memberEntity.Im_qq = memberEntity.Im_msn = memberEntity.In_skype = memberEntity.Im_yahoo = memberEntity.Im_aliww = memberEntity.Outer_id = memberEntity.Feed_config = ""; memberEntity.Portrait = "/Upload/Portrait/1.jpg"; memberEntity.Reg_time = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); memberEntity.Last_login = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); memberEntity.Last_ip = new BasePage().ClientIP; memberEntity.Logins = 0; memberEntity.Ugrade = 1; memberEntity.Status = 1; memberEntity.reward = 0; memberEntity.CNbi = 0; memberEntity.integral = 0; memberEntity.ardent = 0; memberEntity.Growth = 0; memberEntity.code = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Guid.NewGuid().ToString(), "MD5"); memberEntity.Activation = "0"; memberEntity.Describe = ""; memberEntity.Shenjia = 0; memberEntity.Bean = "0"; StringBuilder mailBody = new StringBuilder(); mailBody.AppendFormat(EmailConfig.Instance._EmailBody, memberEntity.nickname, HttpContext.Current.Request.Url.Host, memberEntity.code); //发送注册邮件 b = MemberApi.SendRegisterMail(memberEntity.nickname, memberEntity.code, memberEntity.Email); if (b) { b = MemberBll.Instance.Add(memberEntity) > 0; if (b) { CookieHelper cookieHelper = new CookieHelper("52cos", DateTime.Now.AddMonths(1)); dt = MemberBll.Instance.GetList("Email='" + memberEntity.Email + "' and Password='******'").Tables[0]; cookieHelper.SetCookie("user_id", DEncryptUtils.DESEncrypt(dt.Rows[0]["User_id"].ToString())); //将user_id添加到cookie cookieHelper.SetCookie("pwd", memberEntity.Password); //将Password添加到cookie s = "{\"status\":\"success\"}"; } } context.Response.ContentType = "text/plain"; context.Response.Write(s); }
public ActionResult Register(RegisterViewModel registerViewModel) { if (TempData["VerificationCode"] == null || TempData["VerificationCode"].ToString() != registerViewModel.VerificationCode.ToUpper()) { ModelState.AddModelError("VerificationCode", "验证码不正确"); return(View("Register", registerViewModel)); } var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { Member member = new Member { User_name = "", Portrait = "/Upload/Portrait/1.jpg", Last_login = DateTime.Now, Last_ip = "1.1.1.1", nickname = registerViewModel.NickName, Password = DEncryptUtils.Encrypt3DES(registerViewModel.Password), Status = 1, Reg_time = DateTime.Now }; string str = registerViewModel.Email; if (RegexUtil.IsMobilePhone(str)) //是用手机号注册 { if (TempData["SMSCode"] == null || TempData["SMSCode"].ToString() != registerViewModel.SMSCode.ToUpper()) { ModelState.AddModelError("SMSCode", "短信验证码不正确"); return(View("Register", registerViewModel)); } member.Phone_mob = str; } else //邮箱注册 { member.Email = str; } using (TransactionScope ts = new TransactionScope()) { member = _memberService.Add(member); var lottery = new Lottery() { AcId = 0, AddTime = DateTime.Now, LotteryCode = "0", UserId = member.User_id, Status = 1 }; _lotteryService.Add(lottery); ts.Complete(); } if (member.User_id > 0) { //return Json(new Dictionary<string, string>() { { "status", "success" }, { "message", "注册成功" } }); ViewBag.IsShow = 1; return(View("Register", registerViewModel)); } else { //ModelState.AddModelError("", "注册失败!"); //return JavaScript("alert('服务器异常,请稍后再试!');"); ViewBag.Message = "error"; return(View("Register", registerViewModel)); } } ViewBag.Message = "error"; return(View("Register", registerViewModel)); }
public void ProcessRequest(HttpContext context) { string email = context.Request.Form["user[email]"]; string pwd = context.Request.Form["user[pwd]"]; string remember = context.Request.Form["user[remember]"]; int i = -1; DataTable dt; if (email.IndexOf("@", StringComparison.Ordinal) > -1) { dt = MemberBll.Instance.GetList("Email='" + email + "' AND Password='******'").Tables[0]; } else { dt = MemberBll.Instance.GetList("User_name='" + email + "' AND Password='******'").Tables[0]; } if (dt.Rows.Count > 0) { CookieHelper cookieHelper = null; if (remember == "1") //下次自动登录,设置cookie为一个月 { cookieHelper = new CookieHelper("52cos", DateTime.Now.AddMonths(1)); } else { cookieHelper = new CookieHelper("52cos"); //默认关闭浏览器,失效 } cookieHelper.SetCookie("user_id", DEncryptUtils.DESEncrypt(dt.Rows[0]["User_id"].ToString())); //将user_id添加到cookie cookieHelper.SetCookie("pwd", dt.Rows[0]["Password"].ToString()); //将Password添加到cookie i = 1; } else { i = 0; } context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; context.Response.Write(i); }