Question

Hi i have a class login for check username and password of MYBB from external script its seems work but with small problem. for different users the result return same uid and email for all users (the first uid and email in mybb_users table). pleas how to fix that. thank you for help me.

class Login
{
    function CheckLogin( $username, $password )
    {           

$MySQL_Host = "localhost";
$MySQL_User = "root";
$MySQL_Pass = "";
$MySQL_DB = "";
$tbl_name = "";

    // Connect to server and select databse.
     mysql_connect("$MySQL_Host", "$MySQL_User", "$MySQL_Pass") or die(mysql_error());
    // echo "Connected to MySQL<br />";
     mysql_select_db("$MySQL_DB") or die(mysql_error());
    // echo "Connected to Database<br />";

        $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' =>  $mybb->user['uid'] ,
                          'mail' => $mybb->user[ 'email' ],
                          'user' => $username
                        );
            }
        }
    }
}
Was it helpful?

Solution

Change your script like the following and try it.

return array( 'uid'  => $row['uid'] ,
              'mail' => $row['email'],
              'user' => $username
            );

I think this will work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top