关于PHP中获取随机密码的疑问
- PHP code
<!---ecms 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, <mark style="color:transparent">来4源gaodaimacom搞#代%码*网</mark><code>搞代gaodaima码</code>'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; }
问题1:像这样假如我传一个参数get_random_word(6,13)这样获取的随机单词作为密码使用可靠吗?是否跟使用的单词库有关?
问题2:使用的不是UNIX 这样的单词库我要从哪里找?
问题3:现在建站用户注册遗忘密码这个模块开发还会用这种方式来重置密码吗?
感谢各位解答~~
——解决方案——————–
为什么要用单词…
随机弄一串ASCII字符就行了.
——解决方案——————–
$chars=’ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789′;
我喜欢这样从列出的字符里面随机生成