>  기사  >  백엔드 개발  >  关于PHP中获取随绝密码的疑问

关于PHP中获取随绝密码的疑问

WBOY
WBOY원래의
2016-06-13 10:38:02937검색

关于PHP中获取随机密码的疑问

PHP code
<!--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;  }

问题1:像这样假如我传一个参数get_random_word(6,13)这样获取的随机单词作为密码使用可靠吗?是否跟使用的单词库有关?
问题2:使用的不是UNIX 这样的单词库我要从哪里找?
问题3:现在建站用户注册遗忘密码这个模块开发还会用这种方式来重置密码吗?
感谢各位解答~~

------解决方案--------------------
为什么要用单词...

随机弄一串ASCII字符就行了.
------解决方案--------------------


$chars='ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789';

我喜欢这样从列出的字符里面随机生成
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.