WordPress.org

Ready to get started?Download WordPress

Forums

Ultimate Security Checker
gen_random_string function will never find 36th char (2 posts)

  1. Azizur Rahman
    Member
    Posted 3 years ago #

    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;
        }
  2. bsndev
    Member
    Plugin Author

    Posted 3 years ago #

    thanks! will update the code

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic