從國外網站找到的一款php隨機密碼生成程序哦,先是可以定義基數,然后再利用mt_rand與substr進來取第N個字符。
- <?php
- function genPwd($length=6) {
- $password = '';
- $possible = '23456789bcdfghjkmnpqrstvwxyz';
- $i = 0;
- while ($i < $length) {
- $password .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
- $i++;
- }
- return $password;
- }
- ?>
測試方法,代碼如下:
- <?php
- $password = genPwd(8);
- ?>
新聞熱點
疑難解答