Home > Article > Backend Development > php generates 12 digit random password
This article mainly introduces. Interested friends can refer to php to generate a 12-digit random password. I hope it will be helpful to everyone.
php generates a random password, which is convenient and fast, and can randomly generate safe and reliable passwords.
Share the code as follows
<?php header("Content-type:text/html;charset=utf-8"); function getRandPass($length = 6){ $password = ''; //将你想要的字符添加到下面字符串中,默认是数字0-9和26个英文字母 $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $char_len = strlen($chars); for($i=0;$i<$length;$i++){ $loop = mt_rand(0, ($char_len-1)); //将这个字符串当作一个数组,随机取出一个字符,并循环拼接成你需要的位数 $password .= $chars[$loop]; } return $password; } echo getRandPass(12); //随机生成一个12位数的密码 ?>
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.
Related recommendations:
php methods and examples of making template engines
php methods to achieve hexadecimal conversion
PHP uses Mysqli class library to achieve paging effect and example analysis
The above is the detailed content of php generates 12 digit random password. For more information, please follow other related articles on the PHP Chinese website!