This is a tricky situation. Let me preface what I am going to say with a personal experience.
When I was a sophomore in college, I used to take the train to school. Waiting for my train, a woman approached me and asked me to spare some money because she wanted to buy a bagel. She was kind of worn looking, like she was homeless. I could see the bagel stand from my seat. I gave her $5, which she took and thanked me for. I watched her pass the bagel stand, right out of the train station. I don't know what my $5 bought her, but I can take a guess and assume she didn't buy a bagel. 1 year later, I was taking the train back to school and the SAME woman approached me and asked me for money. It was clear she didn't recognize me. I asked her what she needed it for, and she said a bus ticket. I told her that I would buy the ticket myself and give it to her. She back tracked and said, no, she didn't really need a bus ticket, she needed some food. I said I would buy her a bagel. She told me she didn't want to make me lose my seat to go buy her these things, and I said I didn't mind. Finally she just said forget it, because it was clear that I wasn't just going to hand her money, and she left.
The lesson I learned from this is that it is very important to know where your money is going because not everyone is an honest person (I know, shocker!). Not every person is like this woman, so I never want to generalize people. But, it was clear that I was trying to buy her these things in such a way that I could guarantee where my money was going, and she knew this and freaked out because she clearly wasn't going to buy a ticket or some food if I had simply handed her $5.
I think if anyone finds themselves in a similar situation, it is important to know that you are not being rude if you ask a person approaching you for money, "What are going to buy?" If you feel like you can't trust their answer, you can volunteer to get those things for them yourself. That way, you know where the money is going and they can receive what they asked you for. Or, if you are not financially secure, you can simply volunteer your time instead of your money to anyone. You might not be able to do that for everyone who approaches you on the street, but at least you should have no shame in saying, "I have no money to give you, all I have is my time and energy, is there something else I can do for you?"
In this way, you are clearly opening yourself up to helping someone who might need help, while not giving your money away blindly, and also not just turning someone away who might actually have something they need help with.