Heim  >  Artikel  >  Backend-Entwicklung  >  php生成强密码程序

php生成强密码程序

巴扎黑
巴扎黑Original
2016-11-22 11:49:201614Durchsuche

为大家提供用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);


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn