有这个脚本的人,我可以检查用户名和密码,所以它的 rturn 2 值对我来说
if( $result == false )
{
$packet->AddDWValue( "fail" );
$packet->AddDWValue( "incorrect username and/or password" );
....
如果用户通过 true:
$packet->AddDWValue( "ok" );
$packet->AddDWValue( "nice." );
....
但我还需要检查名为“usergroup”的其他表,因此如果该表的值为“7”,则重新运行其他值,例如:
if( $result == false )
{
$packet->AddDWValue( "fail" );
$packet->AddDWValue( "you are banned" );
....
但我很困惑,如果可能的话,请帮助我。
这是我的代码:
<?
class Login
{
function CheckLogin( $username, $password )
{
$MySQL_Host = "localhost";
$MySQL_User = "1";
$MySQL_Pass = "2";
$MySQL_DB = "3";
$tbl_name = "mybb_users";
mysql_connect("$MySQL_Host", "$MySQL_User", "$MySQL_Pass") or die(mysql_error());
mysql_select_db("$MySQL_DB") or die(mysql_error());
$sql="SELECT * FROM $tbl_name WHERE username='$username'";
$result=mysql_query($sql);
if( $result == false )
return false;
// fwrite($fh, $result);
// fclose($fh);
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if($count==1){
$row = mysql_fetch_assoc($result);
//global $mybb;
if (md5(md5($row['salt']).md5($password)) == $row['password'] ){
return array( 'uid' => $row['uid'] ,
'mail' => $row['email'],
'user' => $username
);
}
}
}
}
class DWAuth
{
var $keys;
function AddDWValue( $val )
{
$this->keys[] = $val;
}
function GetAuthString( )
{
$result = "";
foreach( $this->keys as $c )
{
$result .= $c."#";
}
return $result;
}
}
$login = new Login();
$result = $login->CheckLogin( $result[ 'user' ], $result[ 'pass' ] );
if( $result == false )
{
$packet->AddDWValue( "fail" );
$packet->AddDWValue( "incorrect username and/or password" );
$packet->AddDWValue( 1 );
$packet->AddDWValue( "Anonymous" );
$packet->AddDWValue( "anonymous@example.com" );
$packet->AddDWValue( 0 );
}
else
{
$sessionID = md5( rand() );
$packet->AddDWValue( "ok" );
$packet->AddDWValue( "nice." );
$packet->AddDWValue( $result[ 'uid' ] );
$packet->AddDWValue( $result[ 'user' ] );
$packet->AddDWValue( $result[ 'mail' ] );
$packet->AddDWValue( $sessionID );
}
echo $packet->GetAuthString();
?>