Home >Backend Development >PHP Tutorial >关于PHP中获取随绝密码的疑问
关于PHP中获取随机密码的疑问
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->function get_random_word($min_length, $max_length) $word = ''; $dictionary = '/usr/dict/words'; $fp = @fopen($dictionary, 'r'); if(!$fp) return false; $size = filesize($dictionary); srand ((double) microtime() * 1000000); $rand_location = rand(0, $size); fseek($fp, $rand_location); while (strlen($word)$max_length || strstr($word, "'")) { if (feof($fp)) fseek($fp, 0); // if at end, go to start $word = fgets($fp, 80); // skip first word as it could be partial $word = fgets($fp, 80); // the potential password }; $word=trim($word); // trim the trailing \n from fgets return $word; }