The Prophet ﷺ, when he entered the mosque, would say, "I seek refuge in Allah the Magnificent, in His Noble Face, and in His Eternal Authority, from the accursed Satan."He asked, "Is that all?"I replied, "Yes."He said, "When he says that, Satan says, 'He is protected from me for the rest of the day.'"
عن النبي ﷺ أنه كان إذا دخل المسجد قال: أعوذ بالله العظيم، وبوجهه الكريم، وسلطانه القديم، من الشيطان الرجيم قال: أقط؟ قلت: نعم قال: فإذا قال ذلك: قال الشيطان: حفظ مني سائر اليوم.
Abu Dawud (466) narrated it from Ismail bin Bishr bin Mansur, who said, Abdul-Rahman bin Mahdi narrated to us, from Abdullah bin Mubarak, from Haywa bin Shurayh, who said, I met Uqba bin Muslim and said to him, "It has reached me that you narrate from Abdullah bin Amr bin As, from the Prophet ﷺ, that when he entered the masjid he would say..." and he mentioned something similar.I say, All of its narrators are trustworthy except for Abu Dawud's teacher, Ismail bin Bishr bin Mansur Sulami, who is truthful but was a Qadari, as the author himself stated. Nawawi said in Khulasa (916), "Its chain is good." His words, "Is that all?" mean "is that sufficient," the hamza being for interrogation, meaning he asked, "has only this much reached you from me?" Then he explained to him the additional matter he had beyond what had reached him.As for what has been narrated from Abu Hurairah, attributed to the Prophet, "When one of you enters the masjid, let him greet the Prophet ﷺ with peace and say, 'O Allah, open for me the doors of Your mercy,' and when he leaves, let him greet the Prophet ﷺ with peace and say, 'O Allah, protect me from the accursed devil,'" the correct view is that it stops at the companion.Ibn Majah (773) narrated it, as did Nasai in Amal al-Yawm wal-Layla (90), and from him Ibn Sunni in Amal al-Yawm wal-Layla (86), Ibn Khuzayma (452), and Ibn Hibban (2047) in their two Sahihs, and Hakim in Mustadrak (1/207), all of them through the route of Abu Bakr Hanafi, who said, Dahhak bin Uthman narrated to us, from Saeed Maqburi, from Abu Hurairah, and he mentioned something similar. Hakim graded it sahih according to the standard of Bukhari and Muslim. Busiri said in Zawaid Ibn Majah, "Its chain of transmission is sahih."I say, It is as he said, except that it stops at the companion. Ibn Ajlan opposed him and narrated it from Saeed Maqburi, from Abu Hurairah, that Kaab Ahbar said, "O Abu Hurairah, remember two things from me, I advise you with them, when you enter the masjid, invoke blessings on the Prophet ﷺ and say, 'O Allah, open for me the doors of Your mercy,' and when you leave the masjid, invoke blessings on the Prophet ﷺ and say, 'O Allah, protect me from the devil.'"Nasai narrated it in Amal al-Yawm wal-Layla (91) from Qutayba bin Saeed, who said, Layth narrated to us, and Musaddad, in his Musnad Ithaf Khayra (1445), from Yahya bin Saeed, both of them from Ibn Ajlan with this wording. Ibn Abu Dhib also opposed him, narrating it from Saeed Maqburi with the same wording, as the saying of Kaab, and something similar was narrated from Abu Mashar, also stopping at the companion.So these three, namely Ibn Ajlan, Ibn Abu Dhib, and Abu Mashar, opposed Dahhak bin Uthman in raising the hadith to the Prophet. Dahhak bin Uthman, although he is among the narrators used by Muslim, used to make mistakes. Therefore Abu Hatim said, "His hadith is recorded but not relied upon." Perhaps this flaw was hidden from whoever graded the chain of Dahhak bin Uthman as sahih, and he did not look at those who opposed him in raising the hadith. Hakim erred in placing it according to the standard of Bukhari and Muslim, and the correct view is that it is according to the standard of Muslim alone.There are also narrations on this topic from Anas, Ibn Umar, and Fatimah Zahra, but all of them are daif.