PHP Random string password generation

Source: Internet
Author: User
Tags vars

  1. /**
  2. * @param string $len length
  3. * @param string $type strings type
  4. * 0 Letters 1 numbers other mixes
  5. * @param string $addChars extra characters
  6. * @return String
  7. */
  8. function leipi_rand_string ($len =6,$type =",$addChars =") {
  9. $str =";
  10. switch ($type) {
  11. Case 0:
  12. $chars =' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz '.   $addChars;
  13. Break ;
  14. Case 1:
  15. $chars = str_repeat (' 0123456789 ', 3);
  16. Break ;
  17. Case 2:
  18. $chars =' abcdefghijklmnopqrstuvwxyz '.   $addChars;
  19. Break ;
  20. Case 3:
  21. $chars =' abcdefghijklmnopqrstuvwxyz '.   $addChars;
  22. Break ;
  23. Case 4:
  24. $chars = "Some random Chinese can be entered here. "  $addChars;
  25. Break ;
  26. Default:
  27. //default is to remove the easily confusing characters Ooll and number 01, to add please use the Addchars parameter
  28. $chars =' ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789 '.   $addChars;
  29. Break ;
  30. }
  31. if ($len >10) {//bit too long repeating string a certain number of times
  32. $chars = $type ==1?  str_repeat ($chars,$len): str_repeat ($chars, 5);
  33. }
  34. if ($type!=4) {
  35. $chars = str_shuffle ($chars);
  36. $str = substr ($chars, 0,$len);
  37. }else{
  38. //Chinese random word
  39. For ($i =0; $i <$len; $i + +) {
  40. $str. = Msubstr ($chars, Floor (Mt_rand (0,mb_strlen ($chars,' Utf-8 ')-1)), 1);
  41. }
  42. }
  43. return $str;
  44. }

PHP Random string password generation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.