生成密码函数

<?php
/*
**
** 生成随机密码
**
*/

function createPassword($psdLegth=6){
    $password = "";
    for($i=1;$i<=$psdLegth;$i++){
        $password .= chr(mt_rand(33,126));
    }
    return $password;
}

echo createPassword();

function createPassword1( $length = 6 ) {
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
    $password = '';
    for ( $i = 0; $i < $length; $i++ ){
    // $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
    $password .= $chars[ mt_rand(0, strlen($chars) - 1) ];
    }
    return $password;
}

 

posted @ 2015-03-03 13:00  天道酬勤,坚持!  阅读(439)  评论(0编辑  收藏  举报