You have indeed been ForgivenAnas (Radhi Allahu Anhu) narrated that a man went to the Prophet and said, “O Messenger of Allah, I have perpetrated a sin for which there is a prescribed punishment, so apply it on me.” As it was time for the congregation Prayer, the man then stayed to pray with the Messenger of Allah (Sallallahu Alayhi wa Sallam).
When the Prayer was finished, the man went to the Prophet (Sallallahu Alayhi wa Sallam) and repeated what he had said earlier: “O Messenger of Allah, I have perpetrated a sin for which there is a prescribed punishment, so apply on me that which is in the Book of Allah.”
The Prophet (Sallallahu Alayhi wa Sallam) asked:
“Did you perform Prayer with us?”
“Yes,” said the man.
The Prophet (Sallallahu Alayhi wa Sallam) said:
“Then you have indeed been forgiven.”
(Al-Bukhari and Muslim)