Browse Source

verify master password on reset password enrollment

verifypasswordhashonenrollment
Kyle Spearrin 4 years ago
parent
commit
87f1991e76
  1. 19
      src/Api/Controllers/OrganizationUsersController.cs
  2. 4
      src/Core/Models/Api/Request/Organizations/OrganizationUserRequestModels.cs

19
src/Api/Controllers/OrganizationUsersController.cs

@ -267,10 +267,23 @@ namespace Bit.Api.Controllers
} }
[HttpPut("{userId}/reset-password-enrollment")] [HttpPut("{userId}/reset-password-enrollment")]
public async Task PutResetPasswordEnrollment(string orgId, string userId, [FromBody]OrganizationUserResetPasswordEnrollmentRequestModel model) public async Task PutResetPasswordEnrollment(string orgId, string userId,
[FromBody]OrganizationUserResetPasswordEnrollmentRequestModel model)
{ {
var callingUserId = _userService.GetProperUserId(User); var user = await _userService.GetUserByPrincipalAsync(User);
await _organizationService.UpdateUserResetPasswordEnrollmentAsync(new Guid(orgId), new Guid(userId), model.ResetPasswordKey, callingUserId); if(user == null)
{
throw new UnauthorizedAccessException();
}
if(!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
{
await Task.Delay(2000);
throw new BadRequestException("MasterPasswordHash", "Invalid password.");
}
await _organizationService.UpdateUserResetPasswordEnrollmentAsync(new Guid(orgId),
new Guid(userId), model.ResetPasswordKey, user.Id);
} }
[HttpPut("{id}/reset-password")] [HttpPut("{id}/reset-password")]

4
src/Core/Models/Api/Request/Organizations/OrganizationUserRequestModels.cs

@ -80,6 +80,10 @@ namespace Bit.Core.Models.Api
public class OrganizationUserResetPasswordEnrollmentRequestModel public class OrganizationUserResetPasswordEnrollmentRequestModel
{ {
[Required]
[StringLength(300)]
public string MasterPasswordHash { get; set; }
public string ResetPasswordKey { get; set; } public string ResetPasswordKey { get; set; }
} }

Loading…
Cancel
Save