Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <?php
  2. //方法一
  3. $password_length = 8;
  4.  
  5. function make_seed() {
  6. list($usec, $sec) = explode(' ', microtime());
  7. return (float) $sec + ((float) $usec * 100000);
  8. }
  9.  
  10. srand(make_seed());
  11. // 随机字符总集
  12. $alfa = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
  13. $token = "";
  14. for($i = 0; $i < $password_length; $i ++) {
  15. $token .= $alfa[rand(0, strlen($alfa))];
  16. }
  17. echo $token;
  18. echo '<br>';
  19.  
  20. //方法二
  21. // 创建密码
  22. $totalChar = 9; // 密码中字符串的个数
  23. // salt to select chars from
  24. $salt = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
  25. srand((double)microtime()*1000000); // 启动随机产生器
  26. $Spass = ""; // 设置初始值
  27. for ($i=0;$i<$totalChar;$i++) // 循环创建密码
  28. $Spass .= substr ($salt, rand() % strlen($salt), 1);
  29. echo $Spass;
  30. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement