为大家提供用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<mark>@本文来源gaodaimacom搞#代%码@网-</mark><strong>搞代gaodaima码</strong>($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 fromsrand((double)microtime()*1000000); // start the random generator$Spass=””; // set the inital variablefor ($i=0;$i<$totalChar;$i++) // loop and create password$Spass = $Spass . substr ($salt, rand() % strlen($salt), 1);