生成密碼函式

wensongyu發表於2015-03-03
<?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;
}

 


相關文章