Fixed error with update of password in database

This commit is contained in:
2026-04-16 13:31:35 +01:00
parent 3be49dcdeb
commit 9d08c8a352
3 changed files with 4 additions and 1 deletions
@@ -28,6 +28,7 @@ public class PatchUserPasswordEndpoint(UsersRepository usersRepository, UserServ
} }
string salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next(); string salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
user.Salt = salt;
user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt); user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt);
await usersRepository.SaveChangesAsync(ct); await usersRepository.SaveChangesAsync(ct);
@@ -39,5 +39,6 @@ public class UpdateUserEndpoint(UsersRepository usersRepository, UserService use
await usersRepository.SaveChangesAsync(ct); await usersRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
await Send.OkAsync(await usersRepository.ProjectToSingleAsync<GetUserDetailsDto>(new GetUserByIdSpec(userId), ct), ct);
} }
} }
@@ -12,6 +12,7 @@ public class PatchUserPasswordDtoValidator : Validator<PatchUserPasswordDto>
.NotEmpty() .NotEmpty()
.WithMessage("Password is required") .WithMessage("Password is required")
.MinimumLength(12) .MinimumLength(12)
.WithMessage("Password must exceed 12 characters"); .WithMessage("Password must exceed 12 characters")
.Matches(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*?[#?_!@$%^&*-])");
} }
} }