Random Password Generator in PHP Source Code

When you want a Random Password Generator in PHP Source Code you might think that for example uniquid() is an excellent fit. It’s not though as it will only come back hex figures.

The Random Password Generator in PHP Source Code concept is to mix, A-Z, a-z and 1-9. I’m making zero out of it to prevent misunderstandings between it and O.

As you can see array_rand will come back a unique key from the range that you then can use to get at the value.

First we choose a key for a unique variety (A-Z, a-z or 1-9) in $rkey. Then we choose a unique key from that variety in $vkey, lastly we use the important factors to get at a unique value which we concatenate on the code/password sequence.

However, using array_rand() and range() we can produce Random Password Generator in PHP Source Code a great solution:

 

Random Password Generator in PHP Source Code

function randCode($length = 5){
$ranges = array(range(‘a’, ‘z’), range(‘A’, ‘Z’), range(1, 9));
$code = ”;
for($i = 0; $i < $length; $i++){
$rkey = array_rand($ranges);
$vkey = array_rand($ranges[$rkey]);
$code .= $ranges[$rkey][$vkey];
}
return $code;
}

View all contributions by

    0 comments… add one
    %d bloggers like this: