‘Ali reported God’s messenger as saying, "The covering between the eyes of the jinn and the private parts of the children of Adam when one of them enters the privy is provided by his saying, ‘In the name of God.’”
Tirmidhi transmitted it, saying that this is a gharib tradition and that its isnad is not strong.
Abu Huraira said, "When the Prophet went to the privy I brought him water in a small vessel or a skin and he cleaned himself, after which he wiped his hand on the ground. I then brought him another vessel and he performed ablution.”
Abu Dawud transmitted it, and Darimi and Nasa’i transmitted something similar.
Zaid b. Arqam reported God's messenger as saying, "These privies are peopled by jinn and devils, so when one of you goes there he should say, ‘I seek refuge in God from male and female devils.”