That is exactly the problem in our current situation.
No, you do not. However, there are other solutions. The way it traditionally has been handled is:
1. Voting and citizenship requires 3/4 of your grandparents to have been born in the locale in which you wish to be able to vote.
This stipulation worked very well and would still work very well.
2. No representation without taxation.
This means you must be a net contributor. You must pay more in taxes than you draw in benefits. Paying sales tax from purchases made with welfare checks do not count.
3. Property ownership.
This requirement for voting is not onerous, despite the leftist screeching. You must demonstrate the intention to remain in the community or nation and have a stake in improving it.
If property prices are the problem, then the solution is sacrifice for your right to vote, then use your indignation to demand they stop driving up property prices by importing hordes of migrants.
None of this is tongue in cheek. All of this has been successful in the past. It has been the most successful form of government and arguably the only highly successful form of government.
Every time a nation moves away from these 3 restrictions on voting towards mob-rule democracy, it initiates a collapse of the nation.