Implementation code for generating random usernames and passwords in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:13:17
Original
853 people have browsed it

Sometimes we need to randomly generate usernames and passwords in applications, which can greatly improve the security of the application. To generate random usernames and passwords in PHP, you can use the mt_rand function or the rand function. The rand function is in the verification code. There are more applications, and generating long character random codes generally requires the mt_rand function.

Using PHP to generate random numbers can be used in many places, such as designing random passwords for programs, applications for simulating dice games, rock-paper-scissors game applications, etc.

The following are two function methods for generating random numbers in PHP:

Copy code The code is as follows:

//Automatically generate a random username for the user (length 6-13)
Function Create_password ($ pw_length = 4) {
$ randpwd = '';
for ($ i = 0; $ i & lt; $ i ++) {
$ RANDPWD. = CHR (mt_r_R And (and (and ( " Required characters                                                                                                         any character;
// The second method is to take any element of the character array $chars
1);
                                                                               . //Call this function
$userId = 'user'.generate_username(6);
$pwd = create_password(9);






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

www.bkjia.com

true

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

TechArticle
Sometimes we need to use randomly generated usernames and passwords in applications, which can greatly improve the security of the application. To generate a random username and password in PHP you can use mt...

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!