Alqamah bin Waqas Laithi (may Allah have mercy on him) says that I heard Sayyiduna Umar bin Khattab (may Allah be pleased with him) saying this from the pulpit: "All actions depend upon intentions, and indeed, for every person is what he intended. So, whoever's migration was for Allah and His Messenger, then his migration is (truly) for Allah and His Messenger. And whoever's migration was for worldly gain or to marry a woman, then his migration is for that for which he migrated." This hadith is authentic. Bukhari narrated it from Qanabi, who narrated it from Malik.
Hadith Referenceمسند الشهاب / 1
Hadith Takhrij«أخرجه البخاري 1، أبو داود : 2201 ، وابن ماجه برقم: 4227»