Skip to content

Commit d7bfc6d

Browse files
Fix code scanning alert no. 12: Insecure randomness (#1544)
Signed-off-by: Priyankar Pal <[email protected]> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 22d3eed commit d7bfc6d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/plays/password-generator/PasswordGenerator.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ function PasswordGenerator(props) {
2323

2424
// generate a random number within limit which is provided
2525
const randomNumberGenerator = (limit) => {
26+
const array = new Uint32Array(1);
2627
let result = 0;
2728
while (limit) {
28-
result = Math.floor(Math.random() * Math.floor(Math.random() * 100));
29+
window.crypto.getRandomValues(array);
30+
result = array[0] % limit;
2931
if (result < limit) return result;
30-
31-
continue;
3232
}
3333
};
3434

0 commit comments

Comments
 (0)