Hadith 228

قَالَ أَبُو بَكْرٍ‏:‏ قَدْ أَمْلَيْتُ خَبَرَ عُمَرَ بْنِ الْخَطَّابِ، عَنِ النَّبِيِّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ‏:‏ ‏"‏ الْأَعْمَالُ بِالنِّيَّةِ ‏,‏ وَإِنَّمَا لِامْرِئٍ مَا نَوَى‏.‏
Imam Abu Bakr, may Allah have mercy on him, says that I have narrated from Sayyiduna Umar bin Khattab, may Allah be pleased with him, from the Prophet Muhammad, peace and blessings be upon him, that he said: "Actions are based on intentions, and for every person is what he intended."
Hadith Reference صحيح ابن خزيمه / جماع أبواب غسل الجنابة / 228
Hadith Takhrij صحيح بخاري