When the Apostle of Allaah (sal Allahu alayhi wa sallam) entered the toilet, he used to say (before entering): "O Allaah, I seek refuge in Thee." This is according to the version of Hammad. 'Abd al-Warith has another version :"I seek refuge in Allaah from male and female devils."
كَانَ رَسُولُ اللَّهِ ﷺ إِذَا دَخَلَ الْخَلاَءَ قَالَ عَنْ حَمَّادٍ قَالَ اللَّهُمَّ إِنِّي أَعُوذُ بِكَ وَقَالَ عَنْ عَبْدِ الْوَارِثِ قَالَ أَعُوذُ بِاللَّهِ مِنَ الْخُبُثِ وَالْخَبَائِثِ قَالَ أَبُو دَاوُد رَوَاهُ شُعْبَةُ عَنْ عَبْدِ الْعَزِيزِ اللَّهُمَّ إِنِّي أَعُوذُ بِكَ وَقَالَ مَرَّةً أَعُوذُ بِاللَّهِ و قَالَ وُهَيْبٌ فَلْيَتَعَوَّذْ بِاللَّهِ