下面提供了四款php生成随机密码函数哦,方法简单实用是一款用户自定的加密函数,这样如果不知道你的加密算法是很难破解的.
方法一:
- function generate_password( $length = 8 ) {
-
- $chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
- $password = '';
- for ( $i = 0; $i < $length; $i++ )
- {
-
-
-
-
- $password .= $chars[ mt_rand(0, strlen($chars) - 1) ];
- }
- return $password;
- }
方法二,生成6位数字、字母 混合密码
- $str = "0123456789abcdefghijklmnopqrstuvwxyz";
- $n = 6;
- $len = strlen($str)-1;
- for($j=0 ; $j<200 ; $j++){
- for($i=0 ; $i<$n; $i++){
- $s .= $str[rand(0,$len)];
- }
- echo $s . "
";
- $s = "";
- }
- ?>
-
- $a = "12345678";
- $b = "abcdefghijklmnopqistuvwxyz";
- $s = substr(str_shuffle($a), 0, 2);
- $e = substr(str_shuffle($b), 0, 2);
- echo $s . substr(str_shuffle("!@#$%^&*"), 0, 2) . $e;
- ?>
方法三
- function create_password($pw_length = 8)
- {
- $randpwd = '';
- for ($i = 0; $i < $pw_length; $i++)
- {
- $randpwd .= chr(mt_rand(33, 126));
- }
- return $randpwd;
- }
-
- echo create_password(6);
方法四
- function getmicrotime()
- {
- list($usec, $sec) = explode(" ",microtime());
- return ((float)$usec + (float)$sec);
- }
-
-
- $time_start = getmicrotime();
-
-
-
-
-
- $time_end = getmicrotime();
- $time = $time_end - $time_start;
-
- echo "执行时间 $time seconds";
- ?>
|