Sahih
Al Bukhari
صحيح البخاري
Fasting
كتاب الصوم
Chapter 10: As-Saum for those who fear committing illegal sexual acts
باب الصَّوْمِ لِمَنْ خَافَ عَلَى نَفْسِهِ الْعُزْبَةَ
Sahih Al Bukhari 1905
Narrated 'Alqama
While I was walking with `Abdullah he said, "We were in the company of the Prophet (ﷺ) and he said, 'He who can afford to marry should marry, because it will help him refrain from looking at other women, and save his private parts from committing illegal sexual relation; and he who cannot afford to marry is advised to fast, as fasting will diminish his sexual power."
حَدَّثَنَا عَبْدَانُ، عَنْ أَبِي حَمْزَةَ، عَنِ الأَعْمَشِ، عَنْ إِبْرَاهِيمَ، عَنْ عَلْقَمَةَ، قَالَ بَيْنَا أَنَا أَمْشِي، مَعَ عَبْدِ اللَّهِ ـ رضى الله عنه ـ فَقَالَ كُنَّا مَعَ النَّبِيِّ صلى الله عليه وسلم فَقَالَ " مَنِ اسْتَطَاعَ الْبَاءَةَ فَلْيَتَزَوَّجْ، فَإِنَّهُ أَغَضُّ لِلْبَصَرِ وَأَحْصَنُ لِلْفَرْجِ، وَمَنْ لَمْ يَسْتَطِعْ فَعَلَيْهِ بِالصَّوْمِ، فَإِنَّهُ لَهُ وِجَاءٌ ".