If you have the moregroupware tables in the database as the threads ones, you can simply modify the query.
SELECT U_Number FROM w3t_Users WHERE U_Username=".$conn->QMagic($user)." AND U_Password=".$conn->QMagic($encrypted_pwd);
The next thing you'll have to do is to add all fields to the threads table that mgw needs. I didn't integrate my installation into ubbthreads because I have no need for it. So I can't give you a ready solution. I'll have to look into it first.