It is narrated from Sayyiduna Abu Hurayrah (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "A man said: 'Tonight I will certainly give charity.' So he went out with his charity and (unknowingly) placed it in the hand of an adulteress. In the morning people began talking: 'Last night charity was given to an adulteress.' He said: 'O Allah, all praise is Yours; my charity went to an adulteress?' Then he said: 'Tonight I will certainly give charity.' So he went out with his charity and placed it in the hand of a rich man. In the morning people began talking: 'Last night charity was given to a rich man.' He said: 'O Allah, all praise is Yours; my charity went to a rich man?' Then he said: 'Tonight I will certainly give charity.' He went out with his charity and placed it in the hand of a thief. In the morning people began talking: 'Last night charity was given to a thief.' He said: 'O Allah, all praise is Yours; my charity went to an adulteress, a rich man and a thief?' Then someone came to him and said: 'Your charity has been accepted. As for the adulteress, perhaps because of this charity she will refrain from her adultery; as for the rich man, perhaps he will take a lesson and begin spending from what Allah has given him; and as for the thief, it is hoped that he will refrain from his stealing.'"
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الزكاة / 7846