I am trying to set up a random password generator function in php but this is not working for me. I get the error:
Notice: Array to string conversion in C:\xampp\htdocs\php-testing\index.php on line 12
Array
What am I doing wrong?
<?php
function pwGenerator($len = 10) {
$charRange = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789!@#$%^&*()";
$pw = array();
$length = strlen($charRange);
for ($x = 0; $x < $len; $x++) {
$n = rand(0, $length);
$pw[] = $charRange[$n];
}
return $pw;
}
echo pwGenerator();
It can be an Easy Solution.
The First and the Last character will be only Letter. Middle characters will be Letters, Numbers or Special Characters.