New: Require password confirmation when setting or changing password

(cherry picked from commit b248163df598dc611ee919d525eb7357256d73d5)
This commit is contained in:
Mark McDowall
2023-11-18 18:51:23 -08:00
committed by Bogdan
parent 7fa4daae9b
commit 26a657fa77
6 changed files with 58 additions and 7 deletions
@@ -47,6 +47,9 @@ namespace Prowlarr.Api.V1.Config
SharedValidator.RuleFor(c => c.Password).NotEmpty().When(c => c.AuthenticationMethod == AuthenticationType.Basic ||
c.AuthenticationMethod == AuthenticationType.Forms);
SharedValidator.RuleFor(c => c.PasswordConfirmation)
.Must((resource, p) => IsMatchingPassword(resource)).WithMessage("Must match Password");
SharedValidator.RuleFor(c => c.SslPort).ValidPort().When(c => c.EnableSsl);
SharedValidator.RuleFor(c => c.SslPort).NotEqual(c => c.Port).When(c => c.EnableSsl);
@@ -81,6 +84,23 @@ namespace Prowlarr.Api.V1.Config
return cert != null;
}
private bool IsMatchingPassword(HostConfigResource resource)
{
var user = _userService.FindUser();
if (user != null && user.Password == resource.Password)
{
return true;
}
if (resource.Password == resource.PasswordConfirmation)
{
return true;
}
return false;
}
public override HostConfigResource GetResourceById(int id)
{
return GetHostConfig();
@@ -94,11 +114,10 @@ namespace Prowlarr.Api.V1.Config
resource.Id = 1;
var user = _userService.FindUser();
if (user != null)
{
resource.Username = user.Username;
resource.Password = user.Password;
}
resource.Username = user?.Username ?? string.Empty;
resource.Password = user?.Password ?? string.Empty;
resource.PasswordConfirmation = string.Empty;
return resource;
}