public async Task <IResponseDTO> ResetPassword(ResetPasswordVm resetpasswordVm) { var passwordHasher = new PasswordHasher <ApplicationUser>(); var user = await _userManager.FindByEmailAsync(resetpasswordVm.Email); if (!string.IsNullOrEmpty(resetpasswordVm.Password)) { user.PasswordHash = passwordHasher.HashPassword(user, resetpasswordVm.Password); } IdentityResult result = await _userManager.UpdateAsync(user); if (result.Succeeded) { return(new ResponseDTO { Code = 200, Message = "reset password success", Data = result }); } else { return(new ResponseDTO { Code = 403, Message = "reset password faild", Data = result }); } }
public async Task <IActionResult> OnPost(ResetPasswordVm resetPasswordVm) { if (ModelState.IsValid) { var user = await userManager.FindByEmailAsync(resetPasswordVm.Email); if (user != null) { var result = await userManager.ResetPasswordAsync(user, resetPasswordVm.Token, resetPasswordVm.Password); if (!result.Succeeded) { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } return(Page()); } //if (await userManager.IsLockedOutAsync(user)) //{ // await userManager.SetLockoutEndDateAsync(user, DateTimeOffset.UtcNow); //} //return View("Success"); RedirectToPage("./Success"); } //ModelState.AddModelError("", "Invalid Request"); } //return View(); return(Page()); }
public async Task <IActionResult> OnGet() { Email = TempData["email"].ToString(); Token = TempData["token"].ToString(); ResetPasswordVm = new ResetPasswordVm(); ResetPasswordVm.Token = Token; ResetPasswordVm.Email = Email; return(Page()); }
public ActionResult ResetPassword(ResetPasswordVm data) { try { using (_entities) { if (!ModelState.IsValid) { return(View(data)); } var userInfo = _entities.UserMasters.FirstOrDefault(s => s.UserMasterId == data.UserMasterId); if (userInfo != null) { //Create HASH & SALT var salt = Utilities.GenerateSalt(32); var hash = Utilities.GenerateHash(data.Password.Trim(), userInfo.Email.Trim(), salt); userInfo.Salt = salt; userInfo.Hash = hash; userInfo.Tokens = string.Empty; _entities.Entry(userInfo).State = EntityState.Modified; _entities.SaveChanges(); TempData["Success"] = "Your password change successfully"; return(View("Login")); } TempData["Error"] = "Something went wrong. Please try after some time"; } } catch (Exception e) { TempData["Error"] = e.Message; throw; } return(View(data)); }
public async Task <IActionResult> ResetPassword(ResetPasswordVm model) { if (!ModelState.IsValid) { return(View(model)); } var user = await userManager.FindByEmailAsync(model.Email); /* * If there is no user (meaning there is no account with this email), we don't want to dispatch this information to the user * because we want to keep our accounts private. Instead, we show that pasword reset was successful. */ if (user == null) { return(View("ResetPasswordSuccess")); } var result = await userManager.ResetPasswordAsync(user, model.Token, model.Password); if (result.Succeeded) { // If account was locked, unlock it if (await userManager.IsLockedOutAsync(user)) { await userManager.SetLockoutEndDateAsync(user, DateTimeOffset.UtcNow); } TempData["Success"] = "Password was reset successfully."; return(View("ResetPasswordSuccess")); } else { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } return(View(model)); } }
public ActionResult ResetPassword(string id) { try { using (_entities) { var userInfo = _entities.UserMasters.FirstOrDefault(s => s.Tokens == id); if (userInfo != null) { if (userInfo.TokensGenerated != null && userInfo.TokensGenerated.Value.AddHours(24) < DateTime.Now) { TempData["Error"] = "Link expired."; } else { var resetPasswordVm = new ResetPasswordVm { UserMasterId = userInfo.UserMasterId }; return(View(resetPasswordVm)); } } else { TempData["Error"] = "Invalid request found."; } } } catch (Exception e) { TempData["Error"] = e.Message; throw; } return(RedirectToAction("Login")); }
/// <summary> /// Resets a password /// </summary> /// <param name="model">User's data to reset password</param> /// <returns>Task to enable asynchronous execution</returns> public async Task ResetPassword(ResetPasswordVm model) { var user = await UserManager.FindByNameAsync(model.UserName); if(user == null) { throw new TbIdentityException("Find user error."); } var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password); if(result == null || !result.Succeeded) { throw new TbIdentityException("Reset password error.", result); } }
public async Task <ApiResult> ResetPassword(ResetPasswordVm model) { await _userService.ResetPasswordAsync(model.UserName, model.Token, model.Password); return(ApiResult.Ok); }
public async Task <ApiResult> RecoverAccount(ResetPasswordVm model) { await _userService.RecoverUserAsync(model.UserName); return(ApiResult.Ok); }