From 0c354b30d5f7273d262ce5a1220a01320ce0f2aa Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 5 Jul 2023 00:44:51 +0100 Subject: [PATCH] make the random string generator more random - fixing being able to predict the file id more easily --- upload.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/upload.php b/upload.php index a4617ba..e844513 100644 --- a/upload.php +++ b/upload.php @@ -30,9 +30,14 @@ function generateRandomString($length = 10): string $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; + for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; + // Shuffle the characters array + $shuffledCharacters = str_shuffle($characters); + $randomIndex = random_int(0, $charactersLength - 1); + $randomString .= $shuffledCharacters[$randomIndex]; } + return $randomString; }