2014-02-26 179 views
0

當我從「有效字符數組」中產生一個字符數組時,最終的結果是一組隨機的字符,但IN INDER。例如,我將得到34579abopxzBCJMSTXY。隨機數組不能正常工作

include('db.php'); 
//$num= mt_rand(); 
$veces = $_POST['veces']; 
$equipos = $_POST['equipos']; 
$description = $_POST['description']; 
$salt = "oijahsfdapsf80efdjnsdjp"; 
function get_result(){ 
$valid_chars=array("0","1", "2", "3", "4", "5", "6", "7", "8", "9" 
, "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "m", "n", "p", "q", "r", "s", "t",  "u", "v", "w", "x", "y", "z" 
, "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); 

$result=array_rand($valid_chars, 20); //Cantidad de Caracteres 
$result_str=''; 
foreach ($result as $value) 
{ 
$result_str.=$valid_chars[$value]; 
} 
return $result_str; 
} 
$results=array(); 

for ($i=0; $i<=2000; $i++) 
{ 
array_push($results, get_result()); 
} 

$results=array_unique($results); 

$cont=0; 
$results_str=''; 
foreach ($results as $value) 
{ 
$cont++; 
$results_str.=$value.' 
'; 
// Add some salt 
$salt = "oijahsfdapsf80efdjnsdjp"; 
$salt .= $value; //oijahsfdapsf80efdjnsdjp_Plus_RandomString 
$value = $salt; //Change the RandomString to contain our new salted pass 
$value = md5($value); //(cannot be reversed on a rainbow table as we have a secret salt also..) 
$db = new Database(); 
$ins_query = "INSERT INTO licensing(license, computers, state, description) VALUES('{$value}', '{$equipos}', '2', '{$description}')"; // query to insert value 
$db->query($ins_query); 
if ($cont>=$veces) 
    { 
    break; 
    } 
} 
echo '<pre>'; 
echo $results_str; 
echo '</pre>'; 

PHP信息版本5.3.3

輸出例:

1389adehtvwCEKMNQSUY 
15bgmnpruwzAEFHTUVWY 
159bcenqrswxzFKMNQUX 
35bchstvwxyzEGKNQSUV 
124789defgmvyDEHKNRT 
5abefhjprsuwxCDMPQXY 
+1

現在是時候停止使用MD5加密的目的。那裏有更好的選擇。改爲使用其中之一。 –

回答

1
$valid_chars=array("0","1", "2", "3", "4", "5", "6", "7", "8", "9" 
, "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "m", "n", "p", "q", "r", "s", "t",  "u", "v", "w", "x", "y", "z" 
, "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); 

$result=array_rand($valid_chars, 20); 
$i=0; 
foreach ($result as $value) 
{ 
$result[$i]=$valid_chars[$value]; 
$i++; 
} 


foreach ($result as $v) { 
    echo "$v"; 
} 
echo "<br>"; 

shuffle($result); 
foreach ($result as $v) { 
    echo "$v"; 
} 

Ť他會迴應

0128acfknqrsxCJMPQRS //your string in "order" 
PrMxR0k8nqJCQcS2sfa1