Custom function to generate random password in php

WBOY
Release: 2016-07-25 08:51:28
Original
875 people have browsed it
  1. /*
  2. * php automatically generates new password custom function (with example demonstration)
  3. Applicable environment: PHP5.2.x / mysql 5.0.x
  4. Code author: xujiajay
  5. Contact information: xujiaphp@gmail.com
  6. * */
  7. function genPassword($min = 5, $max = 8)
  8. {
  9. $validchars="abcdefghijklmnopqrstuvwxyz123456789";
  10. $max_char=strlen($validchars)-1;
  11. $length=mt_rand ($min,$max);
  12. $password = "";
  13. for($i=0;$i<$length;$i++ )
  14. {
  15. $password.=$validchars[mt_rand(0,$max_char)] ;
  16. }
  17. return $password;
  18. }
  19. echo "New password:".genPassword()."
    ";
  20. echo "New password:".genPassword(5,10)."
    " ;
  21. ?>
Copy code


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