php 密碼生成類

2021-06-19 21:13:04 字數 2075 閱讀 5484

php 密碼生成類

功能:

1.可設定密碼長度。

2.可設定要生成的密碼個數,批量生成。

3.可以指定密碼的規則,字母,數字,特殊字元等。

generatepassword.class.php

<?php

/** generate password class,根據指定規則生成password

* date: 2013-12-23

* author: fdipzone

* ver: 1.0

** func:

* public batchgenerate 批量生成密碼

* private generate 生成單個密碼

* private getletter 獲取字母

* private getnumber 獲取數字

* private getspecial 獲取特殊字元

*/class generatepassword

if(isset($num) && is_numeric($num) && $num>0 && $num<=100)

if(isset($special) && is_string($special) && $special!='')

if($rule)

if(isset($rule['number']) && in_array($rule['number'], array(1,2)))

if(isset($rule['special']) && in_array($rule['special'], array(1,2)))

if($t_rule)}}

/** 批量生成密碼

* @return array

*/public function batchgenerate()

return $passwords;

}/** 生成單個密碼

* @return string

*/private function generate()

$pool .= $letter;

}if(isset($this->_rule['number']))

$pool .= $number;

}if(isset($this->_rule['special']))

$pool .= $special;

}$pool = str_shuffle($pool); // 隨機打亂

$password = str_shuffle($force_pool. substr($pool, 0, $this->_length-strlen($force_pool))); // 再次隨機打亂

return $password;

}/** 字母 */

private function getletter()

/** 數字 */

private function getnumber()

/** 特殊字元 */

private function getspecial()

} // class end

?>

demo:

<?php

require 'generatepassword.class.php';

$rule = array(

'letter' => 5, // 必須含有大小寫字母

'number' => 2, // 必須含有數字

'special' => 2 // 必須含有特殊字元

);$special = '!@#$%_-';

$obj = new generatepassword(8, 10, $rule, $special);

$passwords = $obj->batchgenerate();

echo implode('

', $passwords);

?>

php 密碼生成類

php 密碼生成類 功能 1.可設定密碼長度。2.可設定要生成的密碼個數,批量生成。3.可以指定密碼的規則,字母,數字,特殊字元等。generatepassword.class.php generate password class,根據指定規則生成password date 2013 12 23 ...

php密碼生成類例項

一 php密碼生成類功能 1.可設定密碼長度。2.可設定要生成的密碼個數,批量生成。3.可以指定密碼的規則,字母,數字,特殊字元等。二 用法 generatepassword.class.php類檔案如下 date 2013 12 23 author fdipzone ver 1.0 func pu...

php生成隨機密碼

隨機密碼生成 post number 0 數字 0 不啟用 1 啟用 post lowercase 0 小寫字母 post uppercase 0 大寫字母 post punctuation 1 特殊符號 post repeat 0 字元 1重複 0不重複 post length 31 密碼長度 p...