Home > php教程 > php手册 > PHP两种方法生成强密码

PHP两种方法生成强密码

WBOY
Release: 2016-06-13 09:38:09
Original
825 people have browsed it

效果演示

第一种生成方式: o6rkNmI0f

第二种生成方式: 745IFsXt?

PHP代码

第一种生成方式

<?php
	$password_length = 9;
	
	function make_seed() {
		list($usec, $sec) = explode(' ', microtime());
		return (float) $sec + ((float) $usec * 100000);
	}
	
	srand(make_seed());
	// 随机字符总集
	$alfa = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
	$token = "";
	for($i = 0; $i < $password_length; $i ++) {
		$token .= $alfa[rand(0, strlen($alfa))];
	}
	echo $token;
?>  
Copy after login

第二种生成方式

<?php
	// 创建密码
	$totalChar = 8; // 密码中字符串的个数
    // salt to select chars from
	$salt = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789"; 
	srand((double)microtime()*1000000); // 启动随机产生器
	$Spass=""; // 设置初始值
	for ($i=0;$i<$totalChar;$i++) // 循环创建密码
		$Spass = $Spass . substr ($salt, rand() % strlen($salt), 1);
	echo $Spass;	
?>?  
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template