mirror of
https://github.com/bitwarden/server.git
synced 2026-01-31 14:13:18 +08:00
verify master password on reset password enrollment
This commit is contained in:
@@ -267,10 +267,23 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
|
||||
[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);
|
||||
await _organizationService.UpdateUserResetPasswordEnrollmentAsync(new Guid(orgId), new Guid(userId), model.ResetPasswordKey, callingUserId);
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
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")]
|
||||
|
||||
@@ -80,6 +80,10 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public class OrganizationUserResetPasswordEnrollmentRequestModel
|
||||
{
|
||||
|
||||
[Required]
|
||||
[StringLength(300)]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
public string ResetPasswordKey { get; set; }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user