Narrated Abu Kabshah Al-An’maariy (radiyallaahu-anhu) that Prophet (sallal-laahu-alayhi-wasallam) said: “I swear by Allah regarding three (affairs) which I am going to tell, so remember them. The wealth of a man does not decrease due to (giving) charity; a slave does not exercise patience when oppressed, except that Allah increases his honour; a slave does not open the door of begging, except that Allaah opens for him the door of poverty (or he stated a statement similar to it).”
I am going to tell you (something), so remember it: The worldly life is for four types of people.
[A] A slave whom Allaah has given wealth and knowledge, so he fears his Lord by way of it. He preserves the ties of kinship and acknowledges Allaah’s Rights regarding it. This (type of person) is on the most virtuous position.
[B] A slave whom Allaah has given knowledge but not wealth. He is truthful in his intention and says: `If I had wealth, I would have done the deed of such and such (person).’’ So because of this intention of his, his reward is the same (i.e. the righteous one who has been given wealth and knowledge).
[C] A slave whom Allaah has given wealth but not knowledge. He wastes his wealth out of ignorance. He neither fears Allaah nor does he keep the ties of kinship, nor does he acknowledge Allaah’s rights. This (type of person) is at the evilest position.
[D] A slave whom Allaah has neither given wealth nor knowledge and he says: `If I had wealth, I would have done the deed of such and such (person).’’ So by way of his intention, they are similar (i.e. similar to the evil person who wastes his wealth). 
Shaikh Ubaid (may Allaah preserve him) stated:
The first is a wealthy person who is thankful (to Allaah); so Allaah will raise him to the most virtuous position due to his deed.
The second is a poor person who exercises patience. He is truthful in his intention with regards to spending from that which Allaah has bestowed on him. So Allaah makes him reach the most virtuous position due to his truthful intention.
The third is a boastful wealthy person. He is covetous and stingy; so his deed takes him to the most evil position.
The fourth is a boastful poor person and his intention is evil. So together with his poverty, his intention takes him to the most evil position.
So based on this, we know that by way of truthful intentions Allaah raises the person. And an evil intention debases a person until he finds him/herself in the most evil position. 
Reported by Tirmidhee 2325; Ahmad 18031; Al-Baghawiy 4097
 Source: البيان المرصع شرح القواعد الأربع- pages 8-9. Slightly paraphrased and abridged]