public async Task <ActionResult> ResetPassword([FromBody] PasswordResetDto passwordResetDto) { var user = await userManager.FindByEmailAsync(passwordResetDto.Email); if (!ModelState.IsValid || user == null) { return(BadRequest(ModelState)); } var token = await userManager.GeneratePasswordResetTokenAsync(user); var emailSuccess = await emailService.SendPasswordResetLink( user.Email, user.Name, HttpContext.Request.Scheme + "://" + HttpContext.Request.Host + "/reset-password/" + user.Id + "?token=" + HttpUtility.UrlEncode(token) ); if (emailSuccess) { return(Accepted()); } else { return(this.InternalServerError()); } }
public async Task <ActionResult> ChangePassword(PasswordResetDto pwrDto) { if (pwrDto.Email != (_configuration["Improvised:PwReset:Email"]).ToLower()) { return(Unauthorized()); } var userWhosePwIs2bReset = await _userManager.FindByEmailAsync(pwrDto.Email); // If user searched is not = null, then there is a user registered with this email, hence send back bad request. if (userWhosePwIs2bReset == null) { _logger.LogWarning("Something went wrong code 3"); return(BadRequest("Reset did not work out")); } // Generate email confirmation token required by password reset. var tooken = await _userManager.GeneratePasswordResetTokenAsync(userWhosePwIs2bReset); var result = await _userManager.ResetPasswordAsync(userWhosePwIs2bReset, tooken, pwrDto.Password); if (result.Succeeded) { await _mailService.SendEmailAsync(pwrDto.Email, "Password Reset", "<p>Thanks! Your Password has been reset with the use of the email: " + pwrDto.Email + ".</p>"); var successConf = _confirmResp.ConfirmResponse(true, "Success! " + "Your password has been reset"); return(Ok(successConf)); } return(BadRequest("Password reset failed completely")); }
public async Task <IActionResult> PasswordReset([FromForm] PasswordResetDto passwordResetDto) { if (passwordResetDto.Key == null || !Guid.TryParse(passwordResetDto.Key, out var validGuid)) { TempData["modalMessage"] = "Invalid key provided. Try reset password again."; return(RedirectToAction("showError", "error")); } var keyFromDbResult = await _keyService.GetKeyAsync(new Guid(passwordResetDto.Key), removeKey : true); if (keyFromDbResult.HasError) { TempData["modalMessage"] = keyFromDbResult.Message; return(RedirectToAction("showError", "error")); } var result = await _userService.PasswordReset(passwordResetDto.Email, passwordResetDto.NewPassword); if (result.HasError) { TempData["modalMessage"] = result.Message; return(RedirectToAction("showError", "error")); } ViewData["modalMessage"] = result.Message; return(View("login")); }
public async Task <ApiResponseDto <bool> > ResetPassword(PasswordResetDto passwordResetDto) { var user = await _userRepo.FindUserByResetToken(passwordResetDto.Token); if (user == null) { return(new ApiResponseDto <bool>(404, "Invalid password reset token", "Error reseting password", false)); } int compareDateTime = DateTime.Compare(user.ResetExpiresAt, DateTime.Now); if (compareDateTime < 0) { return(new ApiResponseDto <bool>(400, "Expired reset token, please request for a new reset token", "Error reseting password", false)); } byte[] passwordHash, passwordSalt; CreatePasswordHash(passwordResetDto.Password, out passwordHash, out passwordSalt); user.PasswordSalt = passwordSalt; user.PasswordHash = passwordHash; _userRepo.UpdateUser(user); var isUpdated = await _userRepo.SaveChanges(); if (!isUpdated) { return(new ApiResponseDto <bool>(500, "We encountered an error while trying to reset your password, please try again", "Error reseting password", false)); } return(new ApiResponseDto <bool>(200, "Your password has been updated, login with your new password", null, true)); }
public async Task <TaskResult> ChangePassword(PasswordResetDto data) { var result = await PerformUserAction(data.Email, user => userManager.ResetPasswordAsync(user, data.ResetToken, data.NewPassword), IdentityResult.Failed()); return(result.GetTaskResult()); }
public async Task <ResultHandler> ChangePassword(PasswordResetDto data) { var messageData = new MessageData(data.Email, MessageType.PasswordChange); return(ResultHandler.HandleTaskResult(await repository .ChangePassword(data) .NextAsync(emailService.SendForTaskResult, messageData))); }
public async Task Delete(Guid uuid) { PasswordResetDto passwordResetToDelete = await _context.PasswordReset .FindAsync(uuid); _context.Remove(passwordResetToDelete); await _context.SaveChangesAsync(); }
public async Task ResetPassword([FromBody] PasswordResetDto dto) { if (string.IsNullOrWhiteSpace(dto.PasswordResetToken) || string.IsNullOrWhiteSpace(dto.NewPassword)) { throw new BusinessException(); } await UserAppService.ResetPasswordAsync(dto.UserName, dto.PasswordResetToken, dto.NewPassword); }
public IActionResult ResetPassword([FromForm] PasswordResetDto passwordResetDto) { var result = _authService.ResetPassword(passwordResetDto); if (!result.IsSuccess) { return(BadRequest(result)); } return(Ok(result)); }
public ActionResult ChangePassword(PasswordResetDto model) { var result = _passwordService.CreateNewPassword(model, model.Id); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public async Task <ActionResult> ResetPaswword(PasswordResetDto passwordResetDto) { var user = await _userRepository.GetUserByUsernameAsync(User.GetUsername()); if (user.Password == passwordResetDto.OldPassword) { user.Password = passwordResetDto.NewPassword; } _userRepository.Update(user); if (await _userRepository.SaveAllAsync()) { return(NoContent()); } return(BadRequest("Failed to reset password")); }
public async Task <ActionResult <bool> > ResetPassword(PasswordResetDto passwordResetDto) { if (passwordResetDto.ResetToken.Length != 96) { return(BadRequest("Link is invalid")); } PasswordReset passwordReset = await _dataContext.PasswordReset.FirstOrDefaultAsync(x => x.ResetToken == passwordResetDto.ResetToken); if (passwordReset == null) { return(BadRequest("Link is invalid")); } if (!passwordReset.Active) { return(BadRequest("Link has expired")); } AppUser appUser = await _dataContext.AppUsers.FirstOrDefaultAsync(x => x.EmailAdress == passwordReset.EmailAddres); if (appUser == null) { return(BadRequest("User does not exist")); } using var hmac = new HMACSHA512(); appUser.PasswordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(passwordResetDto.NewPassword)); appUser.PasswordSalt = hmac.Key; passwordReset.Active = false; _dataContext.AppUsers.Update(appUser); _dataContext.PasswordReset.Update(passwordReset); await _dataContext.SaveChangesAsync(); return(true); }
public async Task <ActionResult> ResetPassword(PasswordResetDto resetDto) { var user = await userManager.FindByIdAsync(resetDto.UserId); if (user == null) { return(StatusCode(StatusCodes.Status400BadRequest, new Response { Status = "Error", Message = "User does not exist" })); } var result = await userManager.ResetPasswordAsync(user, resetDto.Token, resetDto.NewPassword); if (!result.Succeeded) { return(StatusCode(StatusCodes.Status400BadRequest, new Response { Status = "Error", Message = "Failed to reset password" })); } return(Ok()); }
public async Task <IActionResult> ResetPassword([FromBody] PasswordResetDto request) { try { await _identityService.ResetPasswordlAsync(request.UserId, request.Token, request.NewPassword); return(NoContent()); } catch (BadRequestException ex) { return(BadRequest(ex.Message)); } catch (NotFoundException ex) { return(NotFound(ex.Message)); } catch (Exception ex) { _logger.LogCritical($"ResetPassword() Error: {ex}"); return(StatusCode(500, "Internal Server Error")); } }
public IResult ResetPassword(PasswordResetDto passwordResetDto) { var userResult = _userService.GetByMail(passwordResetDto.UserEmail) as AppUser; if (userResult == null) { return(new ErrorResult(Message.UserNotFound)); } if (userResult.ActivationCode != passwordResetDto.Code) { return(new ErrorResult(Message.UserNotFound)); } userResult.ActivationCode = Guid.NewGuid(); byte[] passwordHash, passwordSalt; HashingHelper.CreatePasswordHash(passwordResetDto.Password, out passwordHash, out passwordSalt); userResult.PasswordHash = passwordHash; userResult.PasswordSalt = passwordSalt; _userService.UpdateUserCustomer(userResult); return(new SuccessResult(Message.PasswordReseted)); }
public IResult CreateNewPassword(PasswordResetDto passwordResetDto, int id) { var deletedToken = _sifreYenilemeDal.Get(u => u.UserId == id); if (deletedToken != null) { byte[] passwordHash, passwordSalt; HashingHelper.CreatePasswordHash(passwordResetDto.Password, out passwordHash, out passwordSalt); var userExists = _userService.GetById(id); if (userExists == null) { return(new ErrorResult("UserNotFound")); } userExists.PasswordHash = passwordHash; userExists.PasswordSalt = passwordSalt; _userDal.Update(userExists); _sifreYenilemeDal.Delete(deletedToken); return(new SuccessResult("Success password reset!")); } return(new ErrorResult("UserNotFound")); }
public async Task Add(PasswordResetDto passwordReset) { await _context.PasswordReset.AddAsync(passwordReset); await _context.SaveChangesAsync(); }
public async Task SendPasswordResetCode([FromBody] PasswordResetDto dto) { await UserAppService.SendPasswordResetCodeAsync(dto.UserName); }
public async Task <IActionResult> ResetPassword([FromBody] PasswordResetDto passwordResetDto) { var response = await _authServices.ResetPassword(passwordResetDto); return(StatusCode(response.Status, response)); }