//[ValidateAntiForgeryToken] public async Task <IHttpActionResult> ResetPassword(AccountViewModels.ResetPasswordViewModel model, string returnUrl = null) { try { using (Entities db = new Entities()) { AspNetUser user = new AspNetUser(); user = db.AspNetUsers.FirstOrDefault(usr => usr.Email == model.Email); if (user != null) { using (MD5 md5Hash = MD5.Create()) { string passwordhash = PasswordHashHelper.GetMd5Hash(md5Hash, model.Password); user.PasswordHash = passwordhash; } db.AspNetUsers.AddOrUpdate(user); db.SaveChanges(); return(Ok(true)); } else { return(Ok(false)); } } } catch (Exception ex) { return(Ok(false)); } }
public async Task <ActionResult> ResetPassword(AccountViewModels.ResetPasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await UserManager.FindByNameAsync(model.Email); if (user == null) { // Don't reveal that the user does not exist return(RedirectToAction("ResetPasswordConfirmation", "Account")); } var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password); if (result.Succeeded) { return(RedirectToAction("ResetPasswordConfirmation", "Account")); } AddErrors(result); return(View()); }
//[ValidateAntiForgeryToken] public async Task <bool> CheckEmailExist([FromBody] AccountViewModels.ResetPasswordViewModel model, string returnUrl = null) { try { using (Entities db = new Entities()) { var user = db.AspNetUsers.FirstOrDefault(usr => usr.Email == model.Email); if (user == null) { // Don't reveal that the user does not exist //return RedirectToAction(nameof(ResetPasswordConfirmation)); return(false); } else { return(true); } } } catch (Exception ex) { return(false); } }
//[ValidateAntiForgeryToken] public async Task <IHttpActionResult> ForgotPassword(AccountViewModels.ForgotPasswordViewModel model) { try { using (Entities db = new Entities()) { var user = db.AspNetUsers.FirstOrDefault(usr => usr.Email == model.Email); Random rnd = new Random(); var uppercaseLetter = ((char)('a' + rnd.Next(0, 26))).ToString().ToUpper() + rnd.Next(1, 9).ToString() + "!@"; Guid newpassword = Guid.NewGuid(); AccountViewModels.ResetPasswordViewModel resetPasswordViewModel = new AccountViewModels.ResetPasswordViewModel(); resetPasswordViewModel.Email = user.ToString(); resetPasswordViewModel.Password = newpassword.ToString() + uppercaseLetter; resetPasswordViewModel.ConfirmPassword = newpassword.ToString() + uppercaseLetter; await ResetPassword(resetPasswordViewModel); return(Ok(true)); } } catch (Exception ex) { return(Ok(false)); } }