From f493b96be39841ea4a22f6850f9346ab55d2e07e Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Sat, 28 Mar 2026 12:25:54 +0100 Subject: [PATCH] refactor: use random_int() for email change verification codes Replace mt_rand/rand with random_int for stronger randomness guarantees in verification code generation and Blade component keying. Co-Authored-By: Claude Opus 4.6 --- app/Models/User.php | 2 +- .../components/forms/monaco-editor.blade.php | 2 +- tests/Feature/EmailChangeVerificationTest.php | 109 ++++++++++++++++++ tests/Unit/InsecurePrngArchTest.php | 17 +++ 4 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/EmailChangeVerificationTest.php create mode 100644 tests/Unit/InsecurePrngArchTest.php diff --git a/app/Models/User.php b/app/Models/User.php index 4561cddb2..7c68657e7 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -395,7 +395,7 @@ public function canAccessSystemResources(): bool public function requestEmailChange(string $newEmail): void { // Generate 6-digit code - $code = sprintf('%06d', mt_rand(0, 999999)); + $code = sprintf('%06d', random_int(0, 999999)); // Set expiration using config value $expiryMinutes = config('constants.email_change.verification_code_expiry_minutes', 10); diff --git a/resources/views/components/forms/monaco-editor.blade.php b/resources/views/components/forms/monaco-editor.blade.php index e774f5863..1a35be218 100644 --- a/resources/views/components/forms/monaco-editor.blade.php +++ b/resources/views/components/forms/monaco-editor.blade.php @@ -1,4 +1,4 @@ -
+