Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //方法一
- $password_length = 8;
- function make_seed() {
- list($usec, $sec) = explode(' ', microtime());
- return (float) $sec + ((float) $usec * 100000);
- }
- srand(make_seed());
- // 随机字符总集
- $alfa = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
- $token = "";
- for($i = 0; $i < $password_length; $i ++) {
- $token .= $alfa[rand(0, strlen($alfa))];
- }
- echo $token;
- echo '<br>';
- //方法二
- // 创建密码
- $totalChar = 9; // 密码中字符串的个数
- // salt to select chars from
- $salt = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
- srand((double)microtime()*1000000); // 启动随机产生器
- $Spass = ""; // 设置初始值
- for ($i=0;$i<$totalChar;$i++) // 循环创建密码
- $Spass .= substr ($salt, rand() % strlen($salt), 1);
- echo $Spass;
- exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement