Queries and SolutionsCategory: PHPGenerating a random password in php
princy asked 7 years ago

How to generating a random password in php?

1 Answers
bestonetechnologies Staff answered 7 years ago

Try this:

function generatePassword() {
$alpha = ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890’;
$password = array();
$alphaLength = strlen($alpha) – 1;
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$password[] = $alpha[$n];
}
return implode($password);
}

Your Answer

12 + 20 =