Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private async Task<HealthCheckStatus> CheckForHeaders()
var url = _hostingEnvironment.ApplicationMainUrl?.GetLeftPart(UriPartial.Authority);

// Access the site home page and check for the headers
var request = new HttpRequestMessage(HttpMethod.Head, url);
using var request = new HttpRequestMessage(HttpMethod.Head, url);
try
{
using HttpResponseMessage response = await HttpClient.SendAsync(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private async Task<HealthCheckStatus> CheckForValidCertificate()
var urlBuilder = new UriBuilder(_hostingEnvironment.ApplicationMainUrl) { Scheme = Uri.UriSchemeHttps };
Uri url = urlBuilder.Uri;

var request = new HttpRequestMessage(HttpMethod.Head, url);
using var request = new HttpRequestMessage(HttpMethod.Head, url);

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public virtual string DownloadResponse(string url)

using (var request = new HttpRequestMessage(HttpMethod.Get, url))
{
HttpResponseMessage response = _httpClient.SendAsync(request).GetAwaiter().GetResult();
using HttpResponseMessage response = _httpClient.SendAsync(request).GetAwaiter().GetResult();
return response.Content.ReadAsStringAsync().Result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task SaveInstallLogAsync(InstallLog installLog)
_httpClient = new HttpClient();
}

var content = new StringContent(_jsonSerializer.Serialize(installLog), Encoding.UTF8, "application/json");
using var content = new StringContent(_jsonSerializer.Serialize(installLog), Encoding.UTF8, "application/json");

await _httpClient.PostAsync(RestApiInstallUrl, content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public async Task<UpgradeResult> CheckUpgradeAsync(SemVersion version)
_httpClient = new HttpClient();
}

var content = new StringContent(_jsonSerializer.Serialize(new CheckUpgradeDto(version)), Encoding.UTF8, "application/json");
using var content = new StringContent(_jsonSerializer.Serialize(new CheckUpgradeDto(version)), Encoding.UTF8, "application/json");

_httpClient.Timeout = TimeSpan.FromSeconds(1);
HttpResponseMessage task = await _httpClient.PostAsync(RestApiUpgradeChecklUrl, content);
using HttpResponseMessage task = await _httpClient.PostAsync(RestApiUpgradeChecklUrl, content);
var json = await task.Content.ReadAsStringAsync();
UpgradeResult? result = _jsonSerializer.Deserialize<UpgradeResult>(json);

Expand Down
9 changes: 6 additions & 3 deletions src/Umbraco.Core/Security/LegacyPasswordSecurity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ public class LegacyPasswordSecurity
public static string GenerateSalt()
{
var numArray = new byte[16];
new RNGCryptoServiceProvider().GetBytes(numArray);
return Convert.ToBase64String(numArray);
using (var rng = new RNGCryptoServiceProvider())
{
rng.GetBytes(numArray);
return Convert.ToBase64String(numArray);
}
}

// TODO: Remove v11
Expand Down Expand Up @@ -86,7 +89,7 @@ public bool VerifyPassword(string algorithm, string password, string dbPassword)
/// </summary>
public bool VerifyLegacyHashedPassword(string password, string dbPassword)
{
var hashAlgorithm = new HMACSHA1
using var hashAlgorithm = new HMACSHA1
{
// the legacy salt was actually the password :(
Key = Encoding.Unicode.GetBytes(password),
Expand Down
5 changes: 4 additions & 1 deletion src/Umbraco.Core/Security/PasswordGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ public static string GeneratePassword(int length, int numberOfNonAlphanumericCha
var data = new byte[length];
var chArray = new char[length];
var num1 = 0;
new RNGCryptoServiceProvider().GetBytes(data);
using (var rng = new RNGCryptoServiceProvider())
{
rng.GetBytes(data);
}

for (var index = 0; index < length; ++index)
{
Expand Down