Home >Backend Development >PHP Tutorial >PHP Two Methods to Generate Strong Passwords_PHP Tutorial

PHP Two Methods to Generate Strong Passwords_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:33:01805browse

Effect demonstration

The first generation method: o6rkNmI0f

The second generation method: 745IFsXt?

PHP code

The first generation method

<?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;
?>  

The second generation method

<?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;	
?>?  

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/752560.htmlTechArticleThe first generation method of effect demonstration: o6rkNmI0f The second generation method: 745IFsXt? The first generation method of PHP code ?php$password_length = 9;function make_seed() {list($usec, $sec) =...
Statement:
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