diff --git a/src/NuGetGallery/Authentication/AuthenticationService.cs b/src/NuGetGallery/Authentication/AuthenticationService.cs index 870a5b80a3..52cb3c2fd7 100644 --- a/src/NuGetGallery/Authentication/AuthenticationService.cs +++ b/src/NuGetGallery/Authentication/AuthenticationService.cs @@ -402,7 +402,18 @@ public virtual async Task GeneratePasswordResetToken(User user, int expirationIn var passwordCredential = user.Credentials.FirstOrDefault( credential => credential.Type.StartsWith(CredentialTypes.Password.Prefix, StringComparison.OrdinalIgnoreCase)); - await Auditing.SaveAuditRecordAsync(new UserAuditRecord(user, AuditedUserAction.RequestPasswordReset, passwordCredential)); + UserAuditRecord auditRecord; + + if (passwordCredential == null) + { + auditRecord = new UserAuditRecord(user, AuditedUserAction.RequestPasswordReset); + } + else + { + auditRecord = new UserAuditRecord(user, AuditedUserAction.RequestPasswordReset, passwordCredential); + } + + await Auditing.SaveAuditRecordAsync(auditRecord); await Entities.SaveChangesAsync(); }