Sahih Bukhari | Volume 9 | Hadith Number 56

Narrated by Ibn Mas'ud
A man said, "O Allah's Apostle! Shall we be punished for what we did in the Pre-Islamic Period of ignorance?" The Prophet said, "Whoever does good in Islam will not be punished for what he did in the Pre-Islamic Period of ignorance and whoever does evil in Islam will be punished for his former and later (bad deeds)."