11-06-2009, 05:40 AM
Credits and Source: http://www.dreamincode.net/
Description:
Create random passwords with a chosen length and a specified number of numbers. Uses both lower case and capital letters, which are chosen at random. And example is: wep5Q268LtTe
Snippet:
Instructions: Just add to the appropriate page and call the procedure like passwordGen(12,4) for a password 12 letters long with 4 numbers like in the example: wep5Q268LtTe
That's It
Description:
Create random passwords with a chosen length and a specified number of numbers. Uses both lower case and capital letters, which are chosen at random. And example is: wep5Q268LtTe
Snippet:
PHP Code:
function passwordGen($length,$nums){
$lowLet = "abcdefghijklmnopqrstuvwxyz";
$highLet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$numbers = "123456789";
$pass = "";
$i = 1;
While ($i <= $length){
$type = rand(0,1);
if ($type == 0){
if (($length-$i+1) > $nums){
$type2 = rand(0,1);
if ($type2 == 0){
$ran = rand(0,25);
$pass .= $lowLet[$ran];
}else{
$ran = rand(0,25);
$pass .= $highLet[$ran];
}
}else{
$ran = rand(0,8);
$pass .= $numbers[$ran];
$nums--;
}
}else{
if ($nums > 0){
$ran = rand(0,8);
$pass .= $numbers[$ran];
$nums--;
}else{
$type2 = rand(0,1);
if ($type2 == 0){
$ran = rand(0,25);
$pass .= $lowLet[$ran];
}else{
$ran = rand(0,25);
$pass .= $highLet[$ran];
}
}
}
$i++;
}
return $pass;
}
Instructions: Just add to the appropriate page and call the procedure like passwordGen(12,4) for a password 12 letters long with 4 numbers like in the example: wep5Q268LtTe
That's It