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

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
相关推荐
云梦谭3 小时前
AI 生成的FreeSWITCH 呼出流程深度分析freeswitch-1.10.12.-release
java·前端·php
上海云盾-小余4 小时前
DDoS 攻击溯源:DNS 水印标记 + 区块链存证的双保险
区块链·php·ddos
Web极客码4 小时前
CentOS与RHEL安装EPEL源解析错误修复
linux·centos·php
catchadmin4 小时前
如何创建和使用 Shell 脚本实现 PHP 部署自动化
开发语言·自动化·php
杰哥技术分享4 小时前
宿主机(CentOS)没有安装 PHP,但想使用php
linux·centos·php
m0_738120724 小时前
渗透测试——靶机Sar1渗透横向详细过程
开发语言·python·安全·web安全·网络安全·ssh·php
济南壹软网络科技有限公司5 小时前
壹软V4Max 旗舰版:定义新一代盲盒电商生态系统
php·盲盒源码·盲盒h5·国际盲盒源码
BingoGo6 小时前
万物皆字符串 PHP 中的原始类型偏执
后端·php
网络小白不怕黑6 小时前
IPv6核心技术与NDP协议深度解析:从地址架构到邻居发现
开发语言·架构·php
lubiii_7 小时前
Aircrack-ng工具使用原理与实操笔记
开发语言·网络·web安全·php