可阅读随机字符串与随机字符串

1、将创建一个可阅读的字符串,使其更接近词典中的单词,实用且具有密码验证功能。

php 复制代码
/**  
* @param length - length of random string (must be a multiple of 2)  
* @参数length-随机字符串的长度(必须是2的倍数)
*/ 
function readable_random_string($length = 6){
	$conso = array("b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z");
	$vocal = array("a","e","i","o","u");
	$password = "";
	srand ((double)microtime()*1000000);	//srand()-播下随机数发生器种子,microtime --- 返回当前 Unix 时间戳和微秒数
	$max = $length / 2;
	for($i = 0; $i < $max; $i++){
		$password .= $conso[rand(0,20)];
		$password .= $vocal[rand(0,5)];
	}
	return $password;
}

print_r(readable_random_string());
//输出示例为:xaciti

2、创建一个随机字符串,作为用户的随机密码

php 复制代码
/**  
*@param $length - length of random string  
*@length-随机字符串的长度
*/ 

function generate_random_string($length){
	$c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	$rand = "";
	srand((double)microtime()*1000000);
	for($i = 0; $i < $length; $i++){
		$rand .= $c[rand()%strlen($c)];
	}
	return $rand;
}

print_r(generate_random_string(6));
//输出示例为:QNXM5w
相关推荐
q***71852 小时前
QoS质量配置
开发语言·智能路由器·php
tang777894 小时前
如何保护网络隐私?从理解代理IP开始
网络·tcp/ip·php
dreamtm1238 小时前
通俗理解 TCP 拥塞控制:像 “快递员看路况调速”,避免网络 “堵车”
网络·tcp/ip·php
李纲明12 小时前
WordPress外贸成品网站的免费获取渠道
vue·php
泡沫·1 天前
1.DHCP服务
开发语言·php
JaguarJack1 天前
PHP FFI 完整指南
php·服务端
YUJIANYUE1 天前
查立得PHP+mysql个人微博系统V1.0支持图文视频音频文件
mysql·php·音视频
PyHaVolask1 天前
PHP数据库操作实战
数据库·oracle·php
q***78781 天前
PHP操作redis
开发语言·redis·php
i***48611 天前
【漏洞复现】CVE-2019-11043(PHP远程代码执行漏洞)信息安全论文_含漏洞复现完整过程_含Linux环境go语言编译环境安装
linux·golang·php