Home > Backend Development > PHP Tutorial > PHP program to generate strong passwords

PHP program to generate strong passwords

WBOY
Release: 2016-07-25 09:04:20
Original
1124 people have browsed it
  1. /**

  2. php generates strong passwords
  3. linK: bbs.it-home.org 2013/3/2
  4. */
  5. $password_length = 9;

  6. function make_seed() {

  7. list($usec, $sec) = explode(’ ‘, microtime());
  8. return (float) $sec + ((float) $usec * 100000);
  9. }

  10. srand(make_seed());

  11. $alfa = “1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM”;

  12. $token = “”;
  13. for($i = 0; $i < $password_length; $i ++) {
  14. $token .= $alfa[rand(0, strlen($alfa))];
  15. }
  16. echo $token;

  17. //方法2

  18. // Create Password
  19. $totalChar = 8; // number of chars in the password
  20. $salt = “abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789″; // salt to select chars from
  21. srand((double)microtime()*1000000); // start the random generator
  22. $Spass=””; // set the inital variable
  23. for ($i=0;$i<$totalChar;$i++) // loop and create password
  24. $Spass = $Spass . substr ($salt, rand() % strlen($salt), 1);

复制代码


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template