How did Napoleon win the support of the peasantry and the middle class?
Hero-Worship.
Napoleon brought riches, conquests and glories to the nation. The Nationalist French worshipped Napoleon for bringing such fame to Frnace
Napoleon was a war hero before he was anything else. He succeeded where other's had failed at Toulon. Relatively simple, but important. He got some notority from that. He won acclaim from those at the top by successfully defending the Capital from an uprising, but that did little other than move him up the ranks.
His first big fame came against the Austrians in Italy. The French had been fighting and losing and were stagnant there. His soldiers hadn't been paid, didn't have proper clothes and were demoralized in a major way. In very short order he counter-attacked, beat the Austrians repeatedly, took enough money and supplies to feed, clothe and pay the soldiers and drive the Austrians out. He then freed many areas of Italy that had been dominated by the Austrians for quite some time.
This made him a national hero. But it isn't what won him the support of the peasantry and middle class. It just made him famous and popular with his soldiers.
Over the next couple years Napoleon continued having military success and after being 1st Consult in less than 1 year he corrected significant problems France was having with laws and the economy. He not only stabilized, he revolutionized the entire government. He created a codified set of laws which are still in use to this day. But perhaps the most appropriate answer to your question is...
when the poor could not afford food... instead of sending them a BS stimulus check that wasn't worth much, he had the government buy enough bread for everyone and distribute it!!!
He also established schools and revolutionized the educational opportunities in France. Under the Bourbon rule only the rich and elite were able to get an education and have the best opportunities. The French revolution had abolished the monarchy and nobility, but they didn't know what to do next. Napoleon made it work.
It is fair to say that the opportunities and quality of life rose dramatically for the lower and middle classes under Napoleon to a level that had never been seen before and would not be seen again for some time after Napoleon.
When he took over other countries, he gave most of them at least some independence or at least established constitutional governments and gave the citizens significant rights. This included much more rights for women and minorities.
He was a very good administrator and was one of the few dictators who actually had the good of the people first and foremost in his mind and his actions testified to that in deed.
A final note, he established recognition systems to honor those who had been faithful to France or done something great. Not just the rich and not just the military. Citizens could be given honors and he promoted many based on merit, rather than who they knew, though he certain had political appointments.
Napoleon's many military victories won him the admiration of many people. A cult of personality. Napoleon used propaganda extensively to "big up" his victories. This started from earlier military exploits such as at the Siege of Toulon and at the crossing of the Alps.
http://www.powellhistory.com/art/Painting/David%20-%20Napoleon%20Crossing%20the%20Alps.jpg
Notice how Napoleons name is written above Hannibal in the bottom right hand corner
The peasantry were not really aided however skilled workers from the old 3rd estate from the acien regime were allowed to prosper (to some degree) due to the meritocracy which had been set up.