heh, I think I misread your question, and so using global variables is a can-do.
I'm looking more along the lines of authenticate() being part of another class.
Still, if you're looking for something like the alternative I mentioned, it would be:
function authenticate(&$db, $usernamefunction, $passwordfunction) {
global $userdata;
global $username_in_db;
global $db;
$usernamefunction = strtolower($usernamefunction);
$query = "SELECT * FROM users WHERE username =\"".$usernamefunction."\"";
$result = $db->do_query($query);
and then
$db = new Sql_db($dbname, $dbserver, $dbusername, $dbpassword);
$db->connect();
authenticate($db, $foo, $bar);