From 2873998a162474d09bb8ebcd989317ee1057d657 Mon Sep 17 00:00:00 2001 From: Priyankar Pal <88102392+priyankarpal@users.noreply.github.com> Date: Thu, 10 Oct 2024 19:44:32 +0530 Subject: [PATCH] Fix code scanning alert no. 12: Insecure randomness Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Priyankar Pal <88102392+priyankarpal@users.noreply.github.com> --- src/plays/password-generator/PasswordGenerator.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plays/password-generator/PasswordGenerator.jsx b/src/plays/password-generator/PasswordGenerator.jsx index f475d95fa2..935f227cfe 100644 --- a/src/plays/password-generator/PasswordGenerator.jsx +++ b/src/plays/password-generator/PasswordGenerator.jsx @@ -23,12 +23,12 @@ function PasswordGenerator(props) { // generate a random number within limit which is provided const randomNumberGenerator = (limit) => { + const array = new Uint32Array(1); let result = 0; while (limit) { - result = Math.floor(Math.random() * Math.floor(Math.random() * 100)); + window.crypto.getRandomValues(array); + result = array[0] % limit; if (result < limit) return result; - - continue; } };