Home > Backend Development > PHP Tutorial > PHP randomly generates username and random password_PHP tutorial

PHP randomly generates username and random password_PHP tutorial

WBOY
Release: 2016-07-13 17:47:14
Original
1416 people have browsed it

//Automatically generate a random username for the user (length 6-13)

         function create_password($pw_length = 4){

                $randpwd = '';

for ($i = 0; $i < $pw_length; $i++){

                      $randpwd .= chr(mt_rand(33, 126));

                                                                                                                                     

               return $randpwd;

         } 

function generate_username( $length = 6 ) {

// Password character set, you can add any characters you need

                      $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';

                $password = '';

for ( $i = 0; $i < $length; $i++ )

                                                                 

// Here two character acquisition methods

// The first is to use substr to intercept any character in $chars;

// The second method is to take any element of the character array $chars

// $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);

                      $password .= $chars[ mt_rand(0, strlen($chars) - 1) ];

                                                                                                                                     

                return $password;

         } 

             // Call this function

         $userId = 'user'.generate_username(6);

          $pwd = create_password(9);

Excerpted from Hurry’s column


http://www.bkjia.com/PHPjc/478526.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478526.htmlTechArticle//Automatically generate a random username for the user (length 6-13) function create_password($pw_length = 4){ $randpwd = ; for ($i = 0; $i $pw_length; $i++){ $randpwd .= chr(mt_rand(33, 126)); } re...
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