He heard the Messenger of Allah ﷺ say, "When one of you sees a dream that he likes, it is only from Allah, so let him praise Allah for it and speak of what he saw. But when he sees something other than that which he dislikes, it is only from Satan, so let him seek refuge with Allah from its evil and not mention it to anyone, for then it will not harm him."
حدثنا قتيبة بن سعيد حدثنا بكر بن مضر عن ابن الهاد عن عبد الله بن خباب
أنه سمع رسول الله ﷺ يقول إذا رأى أحدكم الرؤيا يحبها فإنما هي من الله فليحمد الله عليها وليحدث بما رأى وإذا رأى غير ذلك مما يكرهه فإنما هي من الشيطان فليستعذ بالله من شرها ولا يذكرها لأحد فإنها لا تضره
Bukhari also narrated it in the Book of Interpretation of Dreams, chapter "Dreams Are From Allah," hadith no. 6985, from the hadith of Yazid bin Abdullah bin Had, through him.And on this subject there is also a report from Abu Qatada [Bukhari, no. 6995].