Maison  >  Article  >  développement back-end  >  php生成强密码程序

php生成强密码程序

巴扎黑
巴扎黑original
2016-11-22 11:49:201615parcourir

为大家提供用php生成强密码的两种方法。
方法一使用时间戳与随机数的方法,生成强密码。
方法二,原理大致相同,但生成的密码复杂度更强。

<?php
/**
  php生成强密码
  linK:www.jbxue.com 2013/3/2
*/
$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;
//方法2
// Create Password
$totalChar = 8; // number of chars in the password
$salt = “abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789″; // salt to select chars from
srand((double)microtime()*1000000); // start the random generator
$Spass=””; // set the inital variable
for ($i=0;$i<$totalChar;$i++) // loop and create password
$Spass = $Spass . substr ($salt, rand() % strlen($salt), 1);


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn