2

我正在尝试添加一个步骤,如果输入的密码包含输入的用户名,那么它会返回错误,即 pass cannot contain username。我说的是“包含”,而不是密码。在那种情况下,我可以简单地做elseif($password == "$user_username") $error .= $lang['46'];}

$user_username = cleanit($_REQUEST['username']);
STemplate::assign('user_username',$user_username);
$password = cleanit($_REQUEST['password']);
STemplate::assign('password',$password);
if($user_username == "")
{
    $error .= $lang['41'];  //Error: Please enter your username
}
elseif(strlen($user_username) < 4) //Your username should have 4 chars 
{
    $error .= $lang['42'];  
}
elseif(!preg_match("/^[a-zA-Z0-9]*$/i",$user_username)) //name only contains letters and numbers
{
    $error .= $lang['43'];
}
elseif(!verify_email_username($user_username)) //username already taken
{
    $error .= $lang['44'];
}
elseif($password == "") //no password entered
{
    $error .= $lang['45'];  
}    
4

3 回答 3

3

只需将此附加到您的条件:

elseif(stristr($password, $username) !== false) // password contains username
{
    $error .= $lang['46'];  
}
于 2012-06-05T22:07:42.000 回答
3

最简单的事情是stripos

$username = "Corbin";
$password = "mynameiscorbin";
if (stripos($password, $username) !== false) {
    //password contains username
}
于 2012-06-05T22:07:49.380 回答
0

我想你正在寻找stripos().

于 2012-06-05T22:07:28.070 回答