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

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
相关推荐
阿海5744 小时前
安装php7.4.33的shell脚本
php·shell
阿海5744 小时前
卸载php的shell脚本
开发语言·php
JienDa4 小时前
JienDa聊PHP:从Laravel到ThinkPHP的现代Web开发实践
前端·php·laravel
catchadmin5 小时前
PHP 8.5 容器化实战指南
开发语言·php
bleach-6 小时前
buuctf系列解题思路祥讲--[ZJCTF 2019]NiZhuanSiWei1——文件包含漏洞和伪协议的利用
安全·web安全·网络安全·php
2501_941982058 小时前
复杂消息格式自动化:图片、视频和自定义卡片的消息体构造
开发语言·php
aml258__10 小时前
一、Cisco(OSPF邻居认证机制实验:明文与加密MD5对比)251211
网络·php·路由器·思科·ospf·端口认证·明文/md5
catchadmin1 天前
用 Laravel 官方 AI 工具提升开发效率 效率提示数倍
人工智能·php·laravel
小白勇闯网安圈1 天前
file_include、easyphp、ics-05
网络安全·php·web
好大哥呀1 天前
PhpStorm 2025.1 PHP 专业开发下载安装中文设置步骤
php