Allah says, "When My servant intends to commit a bad deed, do not record it against him until he actually does it. If he carries it out, record it as one bad deed. If he abandons it for My sake, record it for him as a good deed. And when he intends to do a good deed but does not do it, record it for him as one good deed. If he carries it out, record it for him as ten good deeds, up to seven hundred."
يقول الله إذا أراد عبدي أن يعمل سيئة فلا تكتبوها عليه حتى يعملها، فإن عملها فاكتبوها بمثلها، وإن تركها من أجلي فاكتبوها له حسنة، وإذا أراد أن يعمل حسنة فلم يعملها فاكتبوها له حسنة، فإن عملها فاكتبوها له بعشر أمثالها إلى سبعمائة.
Bukhari narrated it in the Book of Tawhid (7501), and Muslim in the Book of Iman (128:203), both of them through the route of Abu Zinad, from Araj, from Abu Hurairah, who related it. The wording given is Bukhari's, and Muslim's wording is similar. There are other hadiths with the same meaning mentioned in the Book of Zuhd.