Did you give consent to search? Was there "resasonable suspicion" that you were committing a crime?

If you answered "yes" to either, then the search was legal.