First thing's first. Technically, what the police officers did as far as checking your identifications and searching you and your car was legal. The reason it was legal is because you MADE it legal by failing to refuse to be identified and also failing to refuse being searched. Your silence - or, more appropriately your acquiescence - makes the search legal.
You have to assert your rights! What would have happened if, say, your brother had some weed on him that he was taking with him and didn't tell you about? If the car had a previous owner, what if in some forgotten nook or cranny, something illegal had been there? You, your girlfriend and your brother would all be in danger of being arrested and charged with a crime, even if you didn't commit one. You also need to understand that police can make mistakes OR they can just do bad things. It is very possible that you could be charged, tried and convinced of a crime with little or no inculpatory evidence.
When the police come up to you (doesn't matter if you're in your car, walking down the street, whatever) they CAN ask for your ID, but you also CAN refuse to be identified. At that point, one of two things happen. Either you get detained or you are free to go. The only reason they can detain you is if there is a reasonable suspicion that you are involved in some sort of illegal activity, based on some sort of clearly articulable evidence, at which point you must identify yourself if you are being lawfully detained. But refusing do be identified can't really hurt you because if they DO detain you, they were probably going to do it anyway. The best thing to do is to ask the following: "Officer are you detaining me/us, or am I/we free to go?"
At that point, if there is no reasonable suspicion which gives them probable cause, and after asking the above question they do not detain you, you can safely feel free to completely ignore, walk away from or shut the door on them if they do not detain you. Keep in mind it is always best to be polite.
Secondly, if you ever have to get out of your car, SHUT THE DOOR BEHIND YOU. An open door gives him/her a look inside your car, and the "in plain sight rule comes more into effect. Also an open door is pretty much an open invitation to search your car if you do not tell them that they may not search your car.
Here is another important thing - If ever they ask for anything, it means they do not have any sort of probable cause. Even if they TELL you, they still may not have probably cause - police officers ARE allowed to lie in order to make arrests. If the officer already has probably cause to detain and search you, he or she will no matter what you say. In that case, they were trying to find something illegal, but couldn't. If you had simply told them that they were not allowed to search your vehicle, and they still did, it would have been an illegal search which violates your 4th Amendment rights.
Not to go off-subject, but this general rule of thumb applies to a lot of things. If an officer pulls you over for speeding and comes to your window and asks you if you know how fast you were going, ALWAYS say that you thought you were going the speed limit. The reason the officer is ASKING is because s/he is trying to get you to talk yourself into the ticket because they did not get you with a laser/radar gun, pace you or in some other way empirically measure your speed - they just eyeballed it.
What usually happens is, lets say you're going 60 in a 45. Officer pulls you over, and asks you if you know how fast you were going. Most people, thinking they will get off easy if they just say a lesser amount will say something like: "Yeah I think I was going about 50 or so." That is an admission of guilt, thus, you will get a ticket for going 5 over the limit, or whatever speed you SAID you were going.
Anyway, hope this helps, just in case something like this were to happen again, which I hope doesn't. And like just about everyone here is saying, I would absolutely complain about the way you were treated.