Support » Plugin: Ultimate Security Checker » gen_random_string function will never find 36th char

  • strlen($characters) would return 36 but php index starts from 0 and not 1. Which means you’d never have $characters[36] which will return a php notice.

    Here is an updated function:

    private function gen_random_string($len) {
            $length = intval($len);
            $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
            $string = '';
            for ($p = 0; $p < $length; $p++) {
                $string .= $characters[mt_rand(0, strlen($characters)-1)];
            }
            return $string;
        }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘gen_random_string function will never find 36th char’ is closed to new replies.