It is permissible for a person to speak of what Allah has blessed him with of knowledge or hifz (memorization of the Quran) 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 the Quran and seek knowledge, and that is not regarded as the kind of self-praise that is forbidden. Allah 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-Allah ibn Mas’ood (may Allah be pleased with him) said: I recited seventy-odd surahs to the Messenger of Allah (peace and blessings of Allah be upon him) and the Companions of the Messenger of Allah (peace and blessings of Allah be upon him) know that I am the most knowledgeable among them of the Book of Allah. If I knew that anyone was more knowledgeable than me, I would go to him. Narrated by Muslim (4502).
Al-Nawawi (may Allah have mercy on him) said, commenting on this hadeeth (narration): This hadeeth shows that it is permissible for a person to mention virtues and knowledge that he has if there is a need for it.
With regard to the prohibition on praising oneself, this refers to praising oneself unnecessarily, when the motive is boasting and self-admiration. But prominent people often praise 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 ‘Uthman (may Allah be pleased with him) said, when he was under siege that he had supplied equipment to the army that went to Tabuk, and had dug the well of Rumah. And an example of encouragement to others is when Ibn Mas’ood (may Allah be pleased with him) 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, this is better, because his showing it and speaking of it may open the door to the shaytan and cause him to fall into pride and self-admiration.
And Allah knows best.