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

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
相关推荐
星光一影20 分钟前
基于PHP+MySQL+Uniapp的上门家政服务系统源码
开发语言·mysql·uni-app·php
D***t13125 分钟前
PHP在API开发中的框架选择
开发语言·php
默恋~微凉44 分钟前
shell(八)——WEB与Nginx
开发语言·前端·php
4***V20212 小时前
PHP在微服务通信中的消息队列
开发语言·微服务·php
亿坊电商12 小时前
PHP框架 vs 原生开发:移动应用后端开发实战对比!
开发语言·php
n***293214 小时前
PHP安全编程实践
开发语言·安全·php
b***748815 小时前
PHP在电子商务系统中的构建
开发语言·php
BingoGo15 小时前
PHP8.6 新的 RFC 提案 Context Managers 优雅管理资源生命周期
后端·php
JaguarJack16 小时前
PHP8.6 新的 RFC 提案 Context Managers 优雅管理资源生命周期
php·服务端
月下的郁王子17 小时前
进阶学习 PHP 中的二进制和位运算
android·学习·php