Random password example code generated using php

怪我咯
Release: 2023-03-13 14:32:01
Original
1788 people have browsed it

Cryptography is a technique used to obfuscate, which hopes to transform normal (identifiable) information into unrecognizable information. Of course, for a small number of people, this unrecognizable information can be reprocessed and recovered. Password is the general name for "password" in Chinese. The "password" entered when logging into websites, e-mails, and bank withdrawals should strictly speaking be called "passwords" because it is not an "encryption code" in the original sense, but it can also be called a secret number.

This article mainly introduces pure php to generate a 12-digit random password. The generated password is safereliable. Interested friends can refer to

php to generate a random password. Password, convenient and fast, 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 = &#39;&#39;;
 //将你想要的字符添加到下面字符串中,默认是数字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位数的密码

?>
Copy after login

The above is the detailed content of Random password example code generated using php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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