Interview QuestionsCategory: PHPGenerating a random password in php
princy asked 5 months ago

How to generating a random password in php?

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

14 + 6 =