Answered by Sayyidi Habib Umar bin Hafiz (may Allah protect him and benefit us by him)
How can you tell the origin of a dream?
Scholars like Imam al-Ghazali teach us principles for identifying the origin of the passing thoughts (khawatir) that come to the heart. Those thoughts may be divine (directly from Allah), angelic, satanic (from the whisperings of the Devil) or from the lower self (nafs). The same principles may be applied to dreams. So if a dream is followed by a feeling of tranquillity and presence of heart its origin is divine or angelic. If it is followed by a feeling of unsettledness then it is from the lower self or the Devil. If you dream about something you have thought a lot about in the past then this is from the lower self. When you remember Allah afterwards, the effects of dreams that come from the Devil disappear.
If the dream contains encouragement to disobey Allah, become lazy in acts of obedience or hold a bad opinion about someone or harm them then it is from the Devil. Generally speaking, any dream which contains going against the Shariah or against good etiquette (adab) is from the Devil. Any dream which encourages you to do good, have a good opinion of others and increases you in humility is from Allah.
Allah says: Satan threatens you with the prospect of poverty and commands you to do foul deeds; Allah promises you His forgiveness and His abundance: Allah is limitless and all knowing (al-Baqarah, 2:268).