Yes, doing a background check is legal.
Employers have a right to know what type of people they’re hiring. New roommates have the right to check each other’s credentials.
You could also want to look into a prospective internet date or find out where an old friend is.