Mishkat al-Masabih 1876
وَعَنْ أَبِي هُرَيْرَةَ رَضِيَ اللَّهُ عَنْهُ أَنَّ رَسُولَ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ قَالَ: قَالَ رَجُلٌ: لَأَتَصَدَّقَنَّ بِصَدَقَةٍ فَخَرَجَ بِصَدَقَتِهِ فَوَضَعَهَا فِي يَدِ سَارِقٍ فَأَصْبَحُوا يَتَحَدَّثُونَ تصدق عَلَى سَارِقٍ فَقَالَ اللَّهُمَّ لَكَ الْحَمْدُ عَلَى سَارِقٍ لَأَتَصَدَّقَنَّ بِصَدَقَةٍ فَخَرَجَ بِصَدَقَتِهِ فَوَضَعَهَا فِي يَدي زَانِيَةٍ فَأَصْبَحُوا يَتَحَدَّثُونَ تُصُدِّقَ اللَّيْلَةَ عَلَى زَانِيَةٍ فَقَالَ اللَّهُمَّ لَكَ الْحَمْدُ عَلَى زَانِيَةٍ لَأَتَصَدَّقَنَّ بِصَدقَة فَخرج بِصَدَقَتِهِ فوضعها فِي يَدي غَنِي فَأَصْبحُوا يتحدثون تصدق عَلَى غَنِيٍّ فَقَالَ اللَّهُمَّ لَكَ الْحَمْدُ عَلَى سَارِق وعَلى زَانِيَة وعَلى غَنِي فَأُتِيَ فَقِيلَ لَهُ أَمَّا صَدَقَتُكَ عَلَى سَارِقٍ فَلَعَلَّهُ أَنْ يَسْتَعِفَّ عَنْ سَرِقَتِهِ وَأَمَّا الزَّانِيَةُ فَلَعَلَّهَا أَنْ تَسْتَعِفَّ عَنْ زِنَاهَا وَأَمَّا الْغَنِيُّ فَلَعَلَّهُ يَعْتَبِرُ فَيُنْفِقَ مِمَّا أَعْطَاهُ اللَّهُ . مُتَّفَقٌ عَلَيْهِ وَلَفظه للْبُخَارِيّ
From Abu Hurayrah, may Allah be pleased with him: The Messenger of Allah ﷺ said: "A man said: 'I will certainly give a charity.' So he went out with his charity and placed it in the hand of a thief. In the morning, people were saying: 'Charity was given to a thief.' He said: 'O Allah, to You is the praise — [it went] to a thief! I will certainly give a charity.' He went out with his charity and placed it in the hands of a fornicating woman. In the morning, people were saying: 'Last night charity was given to a fornicating woman.' He said: 'O Allah, to You is the praise — [it went] to a fornicating woman! I will certainly give a charity.' He went out with his charity and placed it in the hands of a rich man. In the morning, people were saying: 'Charity was given to a rich man.' He said: 'O Allah, to You is the praise — to a thief, to a fornicating woman and to a rich man!' Then someone came to him and it was said to him: 'As for your charity to a thief, perhaps he will refrain from his stealing. As for the fornicating woman, perhaps she will refrain from her fornication. As for the rich man, perhaps he will take a lesson and spend from what Allah has given him.'" Agreed upon, and the wording is al-Bukhari's.