How to check whether a username is in use?
Drupal 7 has a function to return a user object by username: 

$user = user_load_by_name($name);
if(!$user){
    // User doesn't exist
} 
else {
    // User exists
}


function user_load_by_name

And a function to return a user object by email:

function user_load_by_mail