Sometimes we need to create a random password generator in our web application. This random password will be given to the user. This is a nice idea to force users to use a secure password. This is a working random password generation function for PHP. Just include this function anywhere in your code and then use it.
In this code, I have removed the l and 1 because it can create confusion in passwords. It means, generated password will not contain 1 and l both. If you want to use, you can add it in the code. This code will generate a random password with mixture of characters, numbers and special characters.
You can also see the demo of this password generator function from the link below.
Random Password generator with PHP
$chars = "!@#$%&*()?~abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ023456789";
$i = 0;
$pass = '' ;
while ($i <= 10)
$num = rand(0,$len);
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$newpassword = createRandomPassword();
echo "Your random password is: $newpassword";
You can also improve this function to make it better. If you have better code, you can share it with us and I will be happy to share that code with our readers along with giving you full credits for that code.
If you have any kind of problem in implementing this code, comment below to ask your queries.