public ActionResult ChangePassMultiUser(string key) { if (key == "ChangePassMultiUserNovaon654321") { Sec_UserDal sec_UserDal = new Sec_UserDal(); var listUser = sec_UserDal.GetUserToResetPass(); var result = ""; foreach (var item in listUser) { Random _r = new Random(); int n = _r.Next(100000, 999999); item.Password = Md5Utils.Encryption("Novaon@" + n.ToString()); result = result + "UserName: "******" Password: "******"Novaon@" + n.ToString() + "; "; Sec_UserLogin user = new Sec_UserLogin(); user.UserID = item.UserID; //return Json(new { result = "Error" }, JsonRequestBehavior.AllowGet); var r = sec_UserDal.SavePassword(user, item.Password); } return(Json(new { result = result }, JsonRequestBehavior.AllowGet)); } return(Json(new { result = "Error" }, JsonRequestBehavior.AllowGet)); }
public ActionResult DoChangePassword(Sec_UserModel m, string PasswordNew, string PasswordNewAgain) { SystemMessage Mess = new SystemMessage(); //valid new password: not same to novaon defaulted password, have atleast 10 characters, contain lower case, upper case, special character !@#$%^&*(),.?:{ }|<>, number Regex regex = new Regex(@"^(?=.*[a-z])(?=.*\d)(?=.*[A-Z])(?=.*[!@#$%^&*(),.?:{ }|<>]).{10,}$"); Match match = regex.Match(PasswordNew); if (match.Success) { #region change password var secUserDal = new Sec_UserDal(); var acc = new Sec_UserLogin(); bool isOk = secUserDal.DoLoginAll(m.Email, out acc); var a = Md5Utils.Encryption(m.Password); if (isOk == true) { if (a != acc.Password) { Mess.IsSuccess = false; Mess.Message = AppRes.ComfirmPasswordOld; return(Json(new { result = Mess }, JsonRequestBehavior.AllowGet)); } else { var MD5Passworld = Md5Utils.Encryption(PasswordNew); var result = secUserDal.SavePassword(acc, MD5Passworld); if (result.IsSuccess == true) { Mess.IsSuccess = true; Mess.Message = AppRes.SuccessPassword; FormsAuthentication.SignOut(); //Clear session var current = System.Web.HttpContext.Current; current.Session.Clear(); current.Session.Abandon(); //Clears out Session current.Response.Cookies.Clear(); // clear authentication cookie current.Response.Cookies.Remove(FormsAuthentication.FormsCookieName); current.Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1)); HttpCookie cookie = current.Request.Cookies[FormsAuthentication.FormsCookieName]; new Helper.Security().Logout(System.Web.HttpContext.Current); if (cookie != null) { cookie.Expires = DateTime.Now.AddDays(-1); current.Response.Cookies.Add(cookie); } return(Json(new { result = Mess }, JsonRequestBehavior.AllowGet)); //return RedirectToAction("Login", "Authentication"); } else { Mess.IsSuccess = false; Mess.Message = AppRes.ErrorSavePassworld; return(Json(new { result = Mess }, JsonRequestBehavior.AllowGet)); } } } else { Mess.IsSuccess = false; Mess.Message = AppRes.ErrorSavePassworld; return(Json(new { result = Mess }, JsonRequestBehavior.AllowGet)); } #endregion } else { Mess.IsSuccess = false; Mess.Message = AppRes.PasswordPolicy; return(Json(new { result = Mess }, JsonRequestBehavior.AllowGet)); } }