Praise be to Allah, and peace and blessings be upon the Messenger of Allah. To proceed:
This hadith in its entirety is not established as authentic. Al-Hakim narrated it in Al-Mustadrak and declared it authentic, but Adh-Dhahabi criticized him and said: “Its chain of transmission is obscure.” This is because it contains several narrators whose reliability has not been established or who were considered weak.
It also has another chain containing Abu Harun al-‘Abdi, who was abandoned by the scholars of hadith and accused of lying, so it cannot be relied upon.
However, it is important to distinguish between the hadith in its entirety and some of its meanings that have been established through other hadiths:
This meaning is established through other hadiths, including the hadith of Abu Sa‘id al-Khudri رضي الله عنه, in which the Prophet ﷺ said:
“The Hour will not be established until the earth is filled with oppression, injustice, and transgression. Then a man from my household will emerge and fill it with fairness and justice just as it was filled with oppression and transgression.”
Al-Hakim declared it authentic, Adh-Dhahabi agreed with him, and Al-Albani also authenticated it.
There are hadiths stating that Allah will send abundant rain during the time of the Mahdi, the earth will bring forth its vegetation, and wealth will become plentiful. Among them is the hadith of Abu Sa‘id رضي الله عنه, which states that the Mahdi will live for seven or eight years.
Al-Hakim declared this hadith authentic, Adh-Dhahabi agreed with him, and Al-Albani also authenticated it.
As for the narration that mentions seven, eight, or nine years, its chain contains a weak narrator, so it cannot be relied upon to determine the duration.
This wording occurs in another narration, but its chain of transmission is weak, so it is not established with this wording.
No authentic supporting evidence is known for this part. Therefore, it is not correct to attribute it to the Prophet ﷺ.
The lengthy hadith mentioned above is not authentic in its entirety, and it is not permissible to use all of its wording as though it were established from the Prophet ﷺ.
However, the basic fact that the Mahdi will emerge, that he will be from the household of the Prophet ﷺ, and that he will fill the earth with fairness and justice after oppression has spread is established through other authentic hadiths.
As for the details mentioned in the narration concerning the length of his rule and the abundance of rain, vegetation, and wealth, only what has been established through an authentic chain should be accepted. Wording that has not been established should not be attributed to the Prophet ﷺ.
And Allah knows best.