File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -36,17 +36,25 @@ public function generate()
3636 $ charset = $ this ->config ->getCharset ();
3737 $ length = $ this ->config ->getLength ();
3838
39- $ maxCombinations = pow (strlen ($ this ->config ->getCharset ()), $ this ->config ->getLength ());
39+ $ charsetLength = strlen ($ this ->config ->getCharset ());
40+ $ maxCombinations = pow ($ charsetLength , $ this ->config ->getLength ());
4041
4142 for ($ i = 0 ; $ i < $ this ->config ->getCount (); $ i ++) {
4243 if ($ maxCombinations <= count ($ this ->skipped )) {
4344 throw InvalidConfigException::maxCombinationReached ();
4445 }
4546
47+ $ randomBytes = random_bytes ($ length );
48+
49+ for ($ j = $ length - 1 ; $ j > 0 ; $ j --) {
50+ $ rand = random_int (0 , $ j );
51+ [$ randomBytes [$ j ], $ randomBytes [$ rand ]] = [$ randomBytes [$ rand ], $ randomBytes [$ j ]];
52+ }
53+
4654 $ hash = '' ;
4755
4856 for ($ j = 0 ; $ j < $ length ; $ j ++) {
49- $ hash .= $ charset [rand ( 0 , strlen ( $ charset ) - 1 ) ];
57+ $ hash .= $ charset [ord ( $ randomBytes [ $ j ]) % $ charsetLength ];
5058 }
5159
5260 $ hash = $ this ->config ->getPrefix () . $ hash . $ this ->config ->getSuffix ();
You can’t perform that action at this time.
0 commit comments