Kaab swore to him by Allah who split the sea for Musa, "We find in the Torah that Dawud, the prophet of Allah, when he finished his prayer, would say, 'O Allah, set right for me my religion, which You have made the safeguard of my affairs. Set right for me my worldly life, in which You have placed my livelihood. O Allah, I seek refuge in Your pleasure from Your displeasure, and I seek refuge in Your pardon from Your punishment, and I seek refuge in You from You. None can withhold what You grant, and none can grant what You withhold, and the fortune of the fortunate cannot avail him against You.'"He said, "Kaab told me that Suhayb related to him that Muhammad ﷺ used to say these words upon finishing his prayer."
أن كعبا حلف له بالله الذي فلق البحر لموسى إنا لنجد في التوراة أن داود نبي الله كان إذا انصرف من صلاته قال: اللهم أصلح لي ديني الذي جعلته لي عصمة، وأصلح لي دنياي التي جعلت فيها معاشي، اللهم إني أعوذ برضاك من سخطك، وأعوذ بعفوك من نقمتك، وأعوذ بك منك، لا مانع لما أعطيت، ولا معطي لما منعت، ولا ينفع ذا الجد منك الجد. قال: وحدثني كعب أن صهيبا حدثه أن محمدا ﷺ كان يقولهن عند انصرافه من صلاته.
Nasai (1346), Ibn Khuzayma (745), and Ibn Hibban (2036) all narrated it via Hafs bin Maysara, from Musa bin Uqba, from Ata bin Abu Marwan, from his father, who related it.Ibn Hajar graded it hasan in Nataij Afkar (2/335), and the discussion of it is detailed in the section on prayer.