From ac2f0a3dcf642587bc4cf0f686f5c53b18514a3b Mon Sep 17 00:00:00 2001 From: whoswhip Date: Sat, 21 Feb 2026 01:35:34 -0500 Subject: [PATCH] refactor(backend:utilties): simplify GenerateSecureRandomString --- SharpbinV3.Server/Utilities.cs | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/SharpbinV3.Server/Utilities.cs b/SharpbinV3.Server/Utilities.cs index b1e1d62..fc454af 100644 --- a/SharpbinV3.Server/Utilities.cs +++ b/SharpbinV3.Server/Utilities.cs @@ -14,27 +14,7 @@ namespace SharpbinV3.Server public static string GenerateSecureRandomString(int length) { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - Span buffer = stackalloc byte[128]; - - var result = new char[length]; - int pos = 0; - - while (pos < length) - { - RandomNumberGenerator.Fill(buffer); - - foreach (byte b in buffer) - { - if (b >= 248) - continue; // 248 is the largest multiple of 62 < 256 - - result[pos++] = chars[b % chars.Length]; - if (pos == length) - break; - } - } - - return new string(result); + return RandomNumberGenerator.GetString(chars, length); } public static string ComputeSha256(string input)