Home > php教程 > php手册 > 纯php生成随机密码,php生成

纯php生成随机密码,php生成

WBOY
Release: 2016-06-13 08:52:22
Original
968 people have browsed it

纯php生成随机密码,php生成

php生成一个随机的密码,方便快捷,可以随机生成安全可靠的密码。

分享代码如下

<&#63;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位数的密码

&#63;>
 
Copy after login

 希望本文对大家学习php程序设计有所帮助,大家可以试着更改生成密码位数,希望大家喜欢。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template