Thursday, June 28, 2007

PHP-Generate Random Password

############################################################
Function to Generate Random Password of length n, Default = 6 characters
Usage: $objClass->fnRandomPasswordGenerator(16);
###########################################################
function fnRandomPasswordGenerator($length = 6)
{
$pass = '';
$new = '';

// all the chars we want to use
$all = explode(" ",
"a b c d e f g h i j k l m n o p q r s t u v w x y z "
."A B C D E F G H I J K L M N O P Q R S T U V W X Y Z "
."0 1 2 3 4 5 6 7 8 9");

for($i=0; $i < $length; $i++)
{
srand((double)microtime()*1000000);
$pass .= $all[rand(0,61)];
$arr[] = $all[rand(0,61)];
$new .= $arr[$i];
}

return $new;
}

Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script.

No comments: