diff options
| author | Marc Alexander <admin@m-a-styles.de> | 2018-06-19 13:32:10 +0200 |
|---|---|---|
| committer | Marc Alexander <admin@m-a-styles.de> | 2018-06-19 13:32:10 +0200 |
| commit | 754945e6fffcfe471f75ea90697d50f60fac3ae8 (patch) | |
| tree | 7310de865c7d3d0eeb1a9a128f0ee0dab2883628 | |
| parent | 02cbb864a5b6df62e978a69c368c8ec5ca35d8a3 (diff) | |
| parent | d4d8aec02af958b40a4c0220cc60498cf32c6549 (diff) | |
| download | forums-754945e6fffcfe471f75ea90697d50f60fac3ae8.tar forums-754945e6fffcfe471f75ea90697d50f60fac3ae8.tar.gz forums-754945e6fffcfe471f75ea90697d50f60fac3ae8.tar.bz2 forums-754945e6fffcfe471f75ea90697d50f60fac3ae8.tar.xz forums-754945e6fffcfe471f75ea90697d50f60fac3ae8.zip | |
Merge pull request #5259 from rubencm/ticket/15695
[ticket/15695] Fix gen_rand_string returning less characters than expected
| -rw-r--r-- | phpBB/includes/functions.php | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 270d513a26..97f25cc701 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -66,27 +66,29 @@ function set_var(&$result, $var, $type, $multibyte = false) /** * Generates an alphanumeric random string of given length * -* @param int $num_chars Length of random string, defaults to 8 +* @param int $num_chars Length of random string, defaults to 8. +* This number should be less or equal than 64. * * @return string */ function gen_rand_string($num_chars = 8) { // [a, z] + [0, 9] = 36 - return substr(strtoupper(base_convert(bin2hex(random_bytes($num_chars)), 16, 36)), 0, $num_chars); + return substr(strtoupper(base_convert(bin2hex(random_bytes($num_chars + 1)), 16, 36)), 0, $num_chars); } /** * Generates a user-friendly alphanumeric random string of given length * We remove 0 and O so users cannot confuse those in passwords etc. * -* @param int $num_chars Length of random string, defaults to 8 +* @param int $num_chars Length of random string, defaults to 8. +* This number should be less or equal than 64. * * @return string */ function gen_rand_string_friendly($num_chars = 8) { - $rand_str = bin2hex(random_bytes($num_chars)); + $rand_str = bin2hex(random_bytes($num_chars + 1)); // Remove Z and Y from the base_convert(), replace 0 with Z and O with Y // [a, z] + [0, 9] - {z, y} = [a, z] + [0, 9] - {0, o} = 34 |
