I don't remember where I got this stuff but here's some vBulletin code to SELECT based on username
PHP Code:
$vbulletin->input->clean_array_gpc('r', array(
'username' => TYPE_STR,
'password' => TYPE_STR
));
$username = strip_blank_ascii($vbulletin->GPC['username'], ' ');
// See VBM-635: &#xxx; should be converted to windows-1252 extended char. This may not happen if a browser submits the form. But from API or user manually input, it does.
// See also vB_DataManager_User::verify_username()
$username = preg_replace(
'/&#([0-9]+);/ie',
"convert_unicode_char_to_charset('\\1', vB_Template_Runtime::fetchStyleVar('charset'))",
$username
);
$user = $vbulletin->db->query_first("
SELECT *
FROM " . TABLE_PREFIX . "user
WHERE username = '" . $vbulletin->db->escape_string(htmlspecialchars_uni($username)) . "'
");