From 2a7bd22a7ba41c6e33417e593545d0dd822be992 Mon Sep 17 00:00:00 2001 From: MysticBoy Date: Mon, 19 Sep 2022 08:24:52 +0800 Subject: [PATCH] Make sure that using this pseudorandom number generator is safe here. --- IoTSharp/Controllers/CaptchaController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IoTSharp/Controllers/CaptchaController.cs b/IoTSharp/Controllers/CaptchaController.cs index f9a3bd8e..1621339a 100644 --- a/IoTSharp/Controllers/CaptchaController.cs +++ b/IoTSharp/Controllers/CaptchaController.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Security.Cryptography; namespace IoTSharp.Controllers { @@ -21,7 +22,6 @@ namespace IoTSharp.Controllers [Route("api/[controller]/[action]")] public class CaptchaController : ControllerBase { - private readonly Random random = new Random(); private readonly IEasyCachingProvider _caching; private readonly IWebHostEnvironment _hostingEnvironment; @@ -84,7 +84,7 @@ namespace IoTSharp.Controllers private ModelCaptcha CreateImage() { using var buzzlefile = new MemoryStream(Properties.Resources.ResourceManager.GetObject("buzzle_template_png") as byte[]); - using var orginfile = new MemoryStream(Properties.Resources.ResourceManager.GetObject($"slide{random.Next(1, 9)}_jpg") as byte[]); + using var orginfile = new MemoryStream(Properties.Resources.ResourceManager.GetObject($"slide{RandomNumberGenerator.GetInt32(1,9)}_jpg") as byte[]); using var buzzlefilestream = new SKManagedStream(buzzlefile); using var orginfilestream = new SKManagedStream(orginfile); using var buzzle = SKBitmap.Decode(buzzlefilestream); -- GitLab