It is permissible for a person to speak of what Allaah has blessed him with of knowledge or hifz (memorization of Qur’aan) if that is done so as to ward off harm or to serve the interests of people, such as if he wants to encourage them to memorize Qur’aan and seek knowledge, and that is not regarded as the kind of self-praise that is forbidden. Allaah tells us that Yoosuf (peace be upon him) said (interpretation of the meaning):
“[Yoosuf (Joseph)] said: ‘Set me over the store‑houses of the land; I will indeed guard them with full knowledge” (as a minister of finance in Egypt)’”
‘Abd-Allaah ibn Mas’ood (may Allaah be pleased with him) said: I recited seventy-odd soorahs to the Messenger of Allaah (peace and blessings of Allaah be upon him) and the companions of the Messenger of Allaah (peace and blessings of Allaah be upon him) know that I am the most knowledgeable among them of the Book of Allaah. If I knew that anyone was more knowledgeable than me, I would go to him. Narrated by Muslim (4502).
Al-Nawawi (may Allaah have mercy on him) said, commenting on this hadeeth: This hadeeth shows that it is permissible for a person to mention virtues and knowledge that he has if there is a need for that.
With regard to the prohibition on praising oneself, that refers to praising oneself unnecessarily, when the motive is boasting and self-admiration. But prominent people often praised themselves when there was a need, such as to ward off harm thereby or to achieve something that is in the people’s interests, or to encourage them to acquire knowledge from him, and so on. An example of serving the people’s interests is when Yoosuf (peace be upon him) said: “Set me over the store‑houses of the land; I will indeed guard them with full knowledge”, and an example of warding off harm is when ‘Uthmaan (may Allaah be pleased with him) said, when he was under siege that he had supplied equipment to the army that went to Tabook, and had dug the well of Roomah. And an example of encouragement to others is when Ibn Mas’ood said this (the words quoted above) and when Sahl ibn Sa’d said: There is no one left who has more knowledge of that than me, and when someone else said: You have come to the expert, and so on. End quote.
But whenever a person is able to conceal his knowledge, that is better, because his showing it and speaking of it may open the door to the shaytaan and cause him to fall into pride and self-admiration.
And Allaah knows best.