Page 1 of 1

Generate a Random Password with PHP

New postPosted: Sat Dec 28, 2013 1:54 pm
by Cat
Notes:
1. You can add more charactors, numbers or lower case charactors to '$possible_charactors' is you wish.
2. You can change the string length, for example, echo 'Random_Password(16);' for 16 charactors.

Code: [Select all] [Expand/Collapse] [Download] (Untitled)
<?
function Random_Password($length) {
<? phpdoc("srand") ?>(<? phpdoc("date") ?>("s"));
$possible_charactors = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$string = "";
while(<? phpdoc("strlen") ?>($string)<$length) {
$string .= <? phpdoc("substr") ?>($possible_charactors,(<? phpdoc("rand") ?>()%(<? phpdoc("strlen") ?>($possible_charactors))),1);
}
return($string);
}
<? phpdoc("echo") ?> Random_Password(8);
?>

Demo!


Anyone who wishes to make additions or changes to this tutorial email them to webmaster@linuxguruz.com