PHP 与有条件的
我正在网上搜索随机密码生成器,我
<?php
function generatePassword($length=9, $strength=0) {
$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;
}
?>
从 http 中 发现了这段代码://www.webtoolkit.info/php-random-password-generator.html
我只想问什么&方法?这是一个合乎逻辑的 AND 他只是忘记添加另一个 & 吗?
I was searching the net for a random password generator and I come across this code
<?php
function generatePassword($length=9, $strength=0) {
$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;
}
?>
from http://www.webtoolkit.info/php-random-password-generator.html
and I would just like to ask what & means? Is that a logical AND did he just forget to add another &?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,它是一个按位与。强度被用作标志,对于每个位设置,辅音都会获得额外的设置与其连接的字符。
No, it is a bitwise and. Strength is being used as flags, for each bit set, consonants gets an extra set of characters concatenated to it.
它是按位和运算符。
It is the bitwise and operator.
单个“&”运算符是按位与。他将 $strength 与二进制表示形式 1、2、4,然后是 8 进行 AND 运算。
The single "&" operator is a bitwise and. He is AND-ing $strength with the binary representation of 1, 2, 4, and then 8.