您正在使用 IPV6 [2600:1f28:365:80b0:15ea:26b1:3fed:e32e] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
[公益]保护绿色环境,构建和谐社会      

【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中      
【腾讯云】618年中盛惠,2核2G5M云服务器低至 68元/年       [公益] 地球是我家,绿化靠大家       广州婚姻调查公司      
2025年 七夕节 077
2025年 教师节 089
2026年 元 旦 202
2026年 春 节 249
综合数码金融娱乐服务报刊政府机构 推荐 排名 今日 申请 友情  
您现在的位置:首页 >> PHP >> 内容
本类新增
本类热门
PHP生成随机密码类分享
内容摘要: ?php/***PHP-PasswordGeneratorClass*Version1.0.0**/if(@!is_object($passGen)||!isset($passGen)){$passGen=newPassword;}classPassword{/***大写字母A-Z**@vararray*/protected$uppercase_chars;......
<?php

/**

*PHP-PasswordGeneratorClass

*Version1.0.0

*

*/

if(@!is_object($passGen)||!isset($passGen)){

$passGen=newPassword;

}

classPassword

{

/**

*大写字母A-Z

*

*@vararray

*/

protected$uppercase_chars;

/**

*小写字母a-z

*

*@vararray

*/

protected$lowercase_chars;

/**

*阿拉伯数字0-9

*

*@vararray

*/

protected$number_chars;

/**

*特殊字符

*

*@vararray

*/

protected$special_chars;

/**

*其他特殊字符

*

*@vararray

*/

protected$extra_chars;

/**

*最终用来生成密码的所有字符

*

*@vararray

*/

protected$chars=array();

/**

*密码长度

*

*@vararray

*/

public$length;

/**

*是否使用大写字母

*

*@varboolean

*/

public$uppercase;

/**

*是否使用小写字母

*

*@varboolean

*/

public$lowercase;

/**

*是否使用阿拉伯数字

*

*@varboolean

*/

public$number;

/**

*是否使用特殊字符

*

*@varboolean

*/

public$special;

/**

*是否使用额外的特殊字符

*

*@varboolean

*/

public$extra;

/**

*初始化密码设置

*

*@paramint$length

*/

functionPassword($length=12)

{

$this->length=$length;

$this->configure(true,true,true,false,false);

}

/**

*配置

*/

functionconfigure($uppercase=false,$lowercase=false,$number=false,

$special=false,$extra=false

){

$this->chars=array();

$this->upper_chars=array(

"A","B","C","D","E","F","G","H","I",

"J","K","L","M","N","O","P","Q","R",

"S","T","U","V","W","X","Y","Z"

);

$this->lower_chars=array(

"a","b","c","d","e","f","g","h","i",

"j","k","l","m","n","o","p","q","r",

"s","t","u","v","w","x","y","z"

);

$this->number_chars=array(

"1","2","3","4","5","6","7","8","9","0"

);

$this->special_chars=array(

"!","@","#","$","%","^","&","*","(",")"

);

$this->extra_chars=array(

"[","]","{","}","-","_","+","=","<",

">","?","/","`","~","|",",",".",";",":"

);

if(($this->uppercase=$uppercase)===true){

$this->chars=array_merge($this->chars,$this->upper_chars);

}

if(($this->lowercase=$lowercase)===true){

$this->chars=array_merge($this->chars,$this->lower_chars);

}

if(($this->number=$number)===true){

$this->chars=array_merge($this->chars,$this->number_chars);

}

if(($this->special=$special)===true){

$this->chars=array_merge($this->chars,$this->special_chars);

}

if(($this->extra=$extra)===true){

$this->chars=array_merge($this->chars,$this->extra_chars);

}

$this->chars=array_unique($this->chars);

}

/**

*从字符列中生成随机密码

*

*@returnstring

**/

functiongenerate()

{

if(empty($this->chars)){

returnfalse;

}

$hash='';

$totalChars=count($this->chars)-1;

for($i=0;$i<$this->length;$i++){

$hash.=$this->chars[$this->random(0,$totalChars)];

}

return$hash;

}

/**

*生成随机数字

*

*@returnint

*/

functionrandom($min=0,$max=0)

{

$max_random=4294967295;

$random=uniqid(microtime().mt_rand(),true);

$random=sha1(md5($random));

$value=substr($random,0,8);

$value=abs(hexdec($value));

if($max!=0){

$value=$min+($max-$min+1)*$value/($max_random+1);

}

returnabs(intval($value));

}

}

调用:

<?php

include_once'password.class.php';

echo$passGen->generate();

//FS4yq74e2LeE

版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:php 截取utf-8格式的字符串实例代码

 

下一篇:没有了

发布日期:2025/3/17
手机扫二维码直达本页
发布时间:21:07:40
点  击:18
录  入:伊伊
相关文章
Baidu
YiJiaCMS 7.5.8 build250610(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,创宇云安全提供加速防护
运行时间载入中.....
知道创宇云安全