Home > Backend Development > PHP Tutorial > PHP generates a code that randomly generates a six-digit password

PHP generates a code that randomly generates a six-digit password

WBOY
Release: 2016-07-25 09:04:22
Original
3204 people have browsed it
  1. //Randomly generate a six-digit password Begin
  2. function randStr($len=6,$format='ALL') {
  3. switch($format) {
  4. case 'ALL':
  5. $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~'; break;
  6. case 'CHAR':
  7. $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-@#~'; break;
  8. case 'N UMBER':
  9. $chars='0123456789'; break;
  10. default :
  11. $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';
  12. break;
  13. }
  14. mt_srand((double)microtime()*1000000*getmypid());
  15. $password="";
  16. while(strlen($password )<$len)
  17. $password.=substr($chars,(mt_rand()%strlen($chars)),1);
  18. return $password;
  19. }
  20. //Randomly generate a six-digit passwordEnd
  21. ? >
Copy code

The Script Academy has provided you with a lot of articles about PHP generating random passwords or random numbers. Friends who are interested can read the following articles: php random verification code php generates random verification code (picture and text) PHP function to generate random username and password PHP program for batch generating random usernames Two ways to randomly generate Welfare Lottery numbers using php A piece of code for php to generate random codes Function to generate random numbers using PHP Code to generate a random string using php php creates code that can read random strings php function to randomly output famous quotes PHP code to randomly extract some elements from an array Example of php generating random numbers Very practical 3 PHP random string function generators A simple php function to randomly generate strings Two ways to generate random strings with PHP Two examples of generating random strings with PHP php function to generate random string php random password generation function php generate random username and random password php function to generate random password PHP function to generate random string php custom function to generate random password php function to generate random password Several ways to generate random passwords with php



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