I want to generate a random password based on the monthly names, the function should pick alphabet
from the A to Z
and place to the 5th position of the random password generated?
Problem
I'm a little bit confused about how do I pick the first letter of the $alphabet
base on the January
and place to the 5th position of the random password generated?
For Example If Current Month Is January
if the current month is January then the function should pick A
from
the $alphabet
and place to the 5th position of the random password
generated?
For Example If Current Month Is February
if the current month is February then the function should pick B
from
the $alphabet
and place to the 5th position of the random password
generated
PHP CODE
function randomPassword() {
$currentmonth = date('F');
if($currentmonth == 'January'){
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ";
$random = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array();
$alphaLength = strlen($random) - 1;
for ($i = 0; $i < 5; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $random[$n];
}
return implode($pass);
}
}
echo randomPassword();