返回顶部

收藏

随机读取密码

更多
function random_readable_pwd($length=10){

    // the wordlist from which the password gets generated 
    // (change them as you like)
    $words = 'dog,cat,sheep,sun,sky,red,ball,happy,ice,';
    $words .= 'green,blue,music,movies,radio,green,turbo,';
    $words .= 'mouse,computer,paper,water,fire,storm,chicken,';
    $words .= 'boot,freedom,white,nice,player,small,eyes,';
    $words .= 'path,kid,box,black,flower,ping,pong,smile,';
    $words .= 'coffee,colors,rainbow,plus,king,tv,ring';

    // Split by ",":
    $words = explode(',', $words);
    if (count($words) == 0){ die('Wordlist is empty!'); }

    // Add words while password is smaller than the given length
    $pwd = '';
    while (strlen($pwd) < $length){
        $r = mt_rand(0, count($words)-1);
        $pwd .= $words[$r];
    }

    // append a number at the end if length > 2 and
    // reduce the password size to $length
    $num = mt_rand(1, 99);
    if ($length > 2){
        $pwd = substr($pwd,0,$length-strlen($num)).$num;
    } else { 
        $pwd = substr($pwd, 0, $length);
    }

    return $pwd;
 }
//该片段来自于http://outofmemory.cn

标签:php,安全

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2014-07-08 19:36:49aes 加密类 by 南宫傲
  2. 2014-07-17 19:24:53从360提供的PHP防SQL注入代码改成的一个类 by loking
  3. 2014-07-25 15:45:41php-md5变换算法之密文分割MD5 by 梁方
  4. 2014-07-25 20:41:09产生任意长度的字符串+数字随机数 by 傅小黑
  5. 2014-10-07 20:41:45php防止页面刷新代码 by loking
  6. 2014-11-22 15:21:26XSS安全过滤 by lihuibng
  7. 2014-11-25 14:14:15检验登陆类 by Flio
  8. 2014-07-14 20:01:15php 图片地址处理 by Linland
  9. 2014-07-18 20:05:42检查字符串中是否有外链 by 杨德伟
  10. 2014-07-26 15:01:56遍历树的方法二 by Flio
  11. 2014-07-26 19:45:59php可以逆转的加密类 by 南宫傲

发表评论