//[ValidateAntiForgeryToken] public async Task <ActionResult> Index(LoginModel model, string url) { BL.Login login = new BL.Login(); string ipAddress = Request.UserHostAddress; var user = await UserManager.FindAsync(model.UserName, model.EncryptPassword); var failTimes = login.GetLastHourLoginFailTimes(Request.UserHostAddress); if (user != null) { user.CompanyId = login.GetCompanyId(user.Id); if (failTimes >= 3 && CompareValidationCode(model.ValidationCode)) { ModelState.AddModelError("", ResourceHelper.GetValue("Message_Common_Login_WorngValidationCode")); } else { await UserHelper.SignInAsync(user, false); login.AddValidSuccessHistory(model.UserName, model.EncryptPassword, ipAddress); return(Redirect("~/" + url)); } } else { if (failTimes >= 3 && CompareValidationCode(model.ValidationCode)) { ModelState.AddModelError("", ResourceHelper.GetValue("Message_Common_Login_WorngValidationCode")); } ModelState.AddModelError("", ResourceHelper.GetValue("Message_Common_Login_WorngNameOrPassword")); } SetValidationCode(model, failTimes); login.AddValidFaileHistory(model.UserName, model.EncryptPassword, ipAddress); ViewBag.LoginFailTimes = failTimes + 1; SetValidationCodeToCookie(); return(View("Index", model)); }
public async Task <ActionResult> UserRests(string Email, string UserName) { BL.Login empBL = new BL.Login(); if (empBL.ValiableEmail(Email, UserName) == "true") { return(Json("validateEmail", JsonRequestBehavior.AllowGet)); } else if (empBL.ValiableEmail(Email, UserName) == "error") { return(Json("error", JsonRequestBehavior.AllowGet)); } UserInfo userBL = new UserInfo(); IPasswordPolicy Password = new RandomPassword(); string orginalPassword = Password.GeneratePassword(); string md5Password = HashEncrypt.MD5(orginalPassword); UserInfoItem model = new UserInfoItem(); model = userBL.GetItemByName(UserName); IdentityModel user = await UserManager.FindByNameAsync(UserName); string password = UserManager.PasswordHasher.HashPassword(md5Password); UserStore store = new UserStore(); var set = store.SetPasswordHashAsync(user, password); var results = store.UpdateAsync(user); if (results != null) { userBL.SendEmail(model, orginalPassword, "User_ResetPassword"); return(Json("true", JsonRequestBehavior.AllowGet)); } else { return(Json("false", JsonRequestBehavior.AllowGet)); } }