Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
bayhaqi:452[Chain 1] Abū ʿAbdullāh al-Ḥāfiẓ > Abū Bakr Aḥmad b. Isḥāq al-Faqīh > Muḥammad b. Ayyūb > Mūsá > Ḥammād [Chain 2] Abū ʿAbdullāh al-Ḥāfiẓ > Aḥmad b. Muḥammad b. al-Ḥusayn al-Bayhaqī > Dāwd b. al-Ḥusayn > Yaḥyá b. Yaḥyá > Ḥammād b. Zayd > ʿAbd al-ʿAzīz b. Ṣuhayb > Anas b. Mālik

[Machine] The Prophet, ﷺ , used to say when he entered the bathroom, "Oh Allah, I seek refuge in You from male and female devils." Al-Bukhari said that Musa mentioned it from Hammad, and Muslim narrated it from Yahya bin Yahya. Al-Bukhari also said that Ghundar mentioned it from Shu'bah from Abdul Aziz. And Saeed bin Zaid mentioned it from Abdul Aziz, when he intended to enter the bathroom.  

البيهقي:٤٥٢أَخْبَرَنَا أَبُو عَبْدِ اللهِ الْحَافِظُ ثنا أَبُو بَكْرٍ أَحْمَدُ بْنُ إِسْحَاقَ الْفَقِيهُ ثنا مُحَمَّدُ بْنُ أَيُّوبَ أنا مُوسَى ثنا حَمَّادُ ح وَأَخْبَرَنَا أَبُو عَبْدِ اللهِ الْحَافِظُ قَالَ أَخْبَرَنِي أَحْمَدُ بْنُ مُحَمَّدِ بْنِ الْحُسَيْنِ الْبَيْهَقِيُّ نا دَاودُ بْنُ الْحُسَيْنِ نا يَحْيَى بْنُ يَحْيَى أنا حَمَّادُ بْنُ زَيْدٍ عَنْ عَبْدِ الْعَزِيزِ بْنِ صُهَيْبٍ عَنْ أَنَسِ بْنِ مَالِكٍ قَالَ

كَانَ النَّبِيُّ ﷺ إِذَا دَخَلَ الْخَلَاءَ قَالَ اللهُمَّ إِنِّي أَعُوذُ بِكَ مِنَ الْخُبُثِ وَالْخَبَائِثِ قَالَ الْبُخَارِيُّ قَالَ مُوسَى عَنْ حَمَّادٍ فَذَكَرَهُ وَرَوَاهُ مُسْلِمٌ عَنْ يَحْيَى بْنِ يَحْيَى قَالَ الْبُخَارِيُّ وَقَالَ غُنْدَرُ عَنْ شُعْبَةَ عَنْ عَبْدِ الْعَزِيزِ إِذَا أَتَى الْخَلَاءَ وَقَالَ سَعِيدُ بْنُ زَيْدٍ عَنْ عَبْدِ الْعَزِيزِ إِذَا أَرَادَ أَنْ يَدْخُلَ