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

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
相关推荐
m0_7381207212 分钟前
PHP代码审计基础——超全局变量(三)
开发语言·安全·网络安全·php
m0_738120722 小时前
PHP代码审计基础——面向对象(四)
android·开发语言·网络·安全·github·php
2601_963771372 小时前
10 Best PHP Media CMS and Scripts for Web Creators in 2026
开发语言·前端·php
着迷不白6 小时前
Linux系统故障修复、日志管理与安全加固实战指南
开发语言·php
Bobolink_17 小时前
跨境业务网络环境评估,“干净、一致、独享”三个关键指标
开发语言·网络·php·跨境网络·网络环境
2401_8949155321 小时前
Geo搜索优化排名源码部署搭建全流程详解
android·开发语言·flask·php·精选
2601_963771371 天前
Hardening Enterprise WordPress Sites Against REST API Leaks and Bad Headers
前端·windows·word·php
weixin_BYSJ19871 天前
springboot美食食谱小程序---附源码24044
java·spring boot·python·spring cloud·django·tomcat·php
木木子222 天前
[特殊字符] 音乐播放器——状态驱动的多媒体控制
android·开发语言·华为·php·harmonyos
酷酷的身影2 天前
Drivers/LedManager.cs
开发语言·php