For this reason, the Prophet, peace and blessings be upon him, said in the well-known hadith of Abdullāh ibn Abbās, may Allah be pleased with them both: “Know Allah in times of ease, and He will know you in times of hardship.” 1
Ibn Rajab, may Allah have mercy on him, wrote in a treatise devoted to explaining this hadith: “The meaning is that when a servant fears Allah, observes His limits, and fulfils His rights in times of ease and health, he thereby makes himself known to Allah, and a bond of recognition is established between him and his Lord. His Lord therefore knows him in times of hardship, recognizes the deeds he performed in times of ease, and delivers him from hardships on account of that relationship.… This special relationship is the one referred to in the hadith qudsi: ‘My servant continues to draw near to Me through voluntary acts of worship until I love him’—and continuing to His words—‘If he asks Me, I will surely give him, and if he seeks My protection, I will surely protect him.’ 2” 3.
He then cited al-Dahhāk ibn Qays as saying: “Remember Allah in times of ease, and He will remember you in times of hardship. Jonah, peace be upon him, used to remember Allah; so when he found himself in the belly of the fish, Allah Most High said: ‘Had he not been one of those who glorified Allah, he would certainly have remained in its belly until the Day they are resurrected.’ 4 Pharaoh, however, was a tyrant who was heedless of Allah’s remembrance. When drowning overtook him, he said, ‘I believe!’ But Allah Most High said: ‘Now? When you had disobeyed before and were one of the corrupters?’ 5” Whoever does not know Allah in times of ease cannot expect Allah to know him in times of hardship, either in this world or in the Hereafter.