what does this mean “if ($strength & 2) {” in the following:
I dont understand the $ 2 part…
function generatePassword($length=11, $strength=7) {
$vowels = 'aeuy';
$consonants = 'bdghjmnpqrstvz';
if ($strength & 1) {
$consonants .= 'BDGHJLMNPQRSTVWXZ';
}
if ($strength & 2) {
$vowels .= "AEUY";
}
if ($strength & 4) {
$consonants .= '23456789';
}
if ($strength & 8) {
$consonants .= '@#$%';
}
$password = '';
$alt = time() % 2;
for ($i = 0; $i < $length; $i++) {
if ($alt == 1) {
$password .= $consonants[(rand() % strlen($consonants))];
$alt = 0;
} else {
$password .= $vowels[(rand() % strlen($vowels))];
$alt = 1;
}
}
return $password;
}
&is a bitwise operator. It manipulates the physical bits of a number.&is known as “bitwise AND”. Given two numbers, it will create a new number for all of the shared bits in both numbers.If you line up the bits for two numbers, any matching bits will be in the resulting number.
This is an easy way to store information in a compact manner.