public async Task <bool> ChangePasswordAsync(string employeeId, EmployeeChangePasswordDto changePasswordDto) { var employee = await this.context.Users.SingleOrDefaultAsync(u => u.Id == employeeId); if (employee == null) { throw new NullReferenceException(string.Format(ErrorMessages.EmployeeIdNullReference, employeeId)); } var result = await this.userManger.ChangePasswordAsync(employee, changePasswordDto.CurrentPassword, changePasswordDto.NewPassword); return(result.Succeeded); }
public async Task <IActionResult> ChangePassword([FromBody] EmployeeChangePasswordDto dto) { byte[] passwordHash, passwordSalt; var employee = await this.repo.VerifyEmployee(dto.Email, dto.currentPassword); if (employee == null) { return(Unauthorized()); } this.repo.createPasswordHash(dto.newPassword, out passwordHash, out passwordSalt); employee.PasswordHash = passwordHash; employee.PasswordSalt = passwordSalt; employee.LastUpdated = DateTime.Parse(DateTime.Now.ToString("MM/dd/yyyy H:mm")); await this.repo.SaveChangesAsync(); return(Ok()); }