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

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
相关推荐
万联WANFLOW14 小时前
多分支企业组网,IP 网段到底该怎么规划
开发语言·php
WZF-Sang18 小时前
网络基础——2
服务器·网络·c++·学习·网络编程·php
行思理18 小时前
fastadmin 新手部分功能点
后端·php
用户30745969820719 小时前
# GatewayWorker 入门指南
php
2601_963771371 天前
Optimizing Logistics and Transportation Sites on WordPress
前端·数据库·windows·php
草邦设计开发团队_媒体资源平台1 天前
Linux 稳定常驻启动 PHP 队列,服务器重启自动恢复
linux·服务器·php·队列执行
2601_963771371 天前
Speeding Up Creative Agency Portfolios: A Performance Guide
前端·数据库·php
七夜zippoe1 天前
OpenClaw 数据加密:敏感信息保护的完整方案
数据库·mysql·php·openclaw·敏感保护
烤代码的吐司君2 天前
Redis IO 多路复用原理与引入原因深度解析
数据库·redis·php
鹏易灵2 天前
C++——8.移动语义初探(移动构造、移动赋值)
开发语言·c++·php