mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-26 22:56:23 -04:00
New: Require password confirmation when setting or changing password
This commit is contained in:
committed by
Mark McDowall
parent
d95660d3c7
commit
b248163df5
@@ -47,6 +47,9 @@ namespace Sonarr.Api.V3.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 Sonarr.Api.V3.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;
|
||||
}
|
||||
|
||||
protected override HostConfigResource GetResourceById(int id)
|
||||
{
|
||||
return GetHostConfig();
|
||||
@@ -93,11 +113,10 @@ namespace Sonarr.Api.V3.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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user