Well i was looking for a way to generate random passwords with php, i was building a script that demanded a large amount of them and I wanted also to store them in a txt file for use with another software with such inputs. So I found a way below that I think its quick and very easy for anybody to understand.

<?php
//—First I input a random set of characters.
$characters = “0123456789abcdefghijklmnopqrstuvwxyz”;

//—The amount of random passwords I want, lets say 5000 passwords.
$amount=5000;

//—The amount of characters that I like my passwords to have, lets say 10.
$amountchar=10;

//—I insert a loop for the creation.
for ($i = 0; $i < $amount; $i++) {

//— I unset the keyword that I found in the previous step (thats because ive insert this dot below the string variable).
unset($string);

//— I insert another loop and i say to the script to choose random the amount of characters that i wish for every password.
for ($p = 0; $p < $amountchar; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}

//— I echo my passwords to choose them and copy them in a txt file.
echo $string.”<br>”;
}

?>

Of course instead of echo-ing the strings i could also write my passwords asap in txt with: file_put_contents ( ’some.txt’, $content ); php command!


Share This