Dispose IDisposable instances (#15810)

This commit is contained in:
Chad
2024-03-14 03:59:28 +13:00
committed by GitHub
parent ac5539a8be
commit 2fbda6e64b
7 changed files with 16 additions and 10 deletions

View File

@@ -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
@@ -86,7 +89,7 @@ public class LegacyPasswordSecurity
/// </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),

View File

@@ -98,7 +98,10 @@ public class PasswordGenerator
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)
{