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

How to generating a random password in php?

1 Answers
bestonetechnologies Staff answered 6 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

15 + 17 =