New Delhiinfo-icon:- Indiainfo-icon's top courtinfo-icon on Wednesday upheld the legality of the government's Aadhaar national identity project, the worldinfo-icon's largest biometric database, but imposed new restrictions on how the personal details of more than one billion citizens can be used.

The ruling by a five-judge bench of the Supreme Court draws a line under many years of legal challenges from critics, who said Aadhaar threatened individual privacy and risked turning the world's second-most populous nation into a surveillance state.

The government had insisted Aadhaar, which issues every Indian with a unique 12-digit ID linked to fingerprints and iris scans, would streamline welfare services and root out fraud.

It was also pitched as a transparent way to ensure that government handouts of foodinfo-icon, fuel and other essentials to India's poorest would not be siphoned off by corrupt middlemen, a huge problem in the vast country of 1.25bn.

In its ruling the Supreme Court upheld the legality of the scheme, saying the benefits far outweighed any risks.

The judges ruled that anybody drawing on government services -- from filing tax returns to accessing pensions or welfare -- would by law require an Aadhaar number.

But the bench said corporations could not insist that Indians provide their unique ID to register for services such as phone numbers -- a key complaint from privacy advocates who say Aadhaar had gone too far.

The scheme was rolled out under the previous Congress Party government in 2010 but grew in scope under Indian Prime Minister Narendra Modi, whose Bharatiya Janata Party (BJP) swept to power in 2014.

Initially a voluntary programme, it soon became mandatory for those wishing to access government services, including even schoolchildren wanting free lunches provided by the state.

The court, in its landmark ruling, also said children would not need Aadhaar to enrol in school since a right to education was fundamental to all Indians.

The government went to the Supreme Court last year to argue that Indians did not have a fundamental right to privacy -- a case linked to Aadhaar that it lost.

The Supreme Court in January began hearing a series of challenges to the constitutional validity of Aadhaar, a Hindi word meaning "foundation".

"I am happy with the Aadhaar ruling. It should be made mandatory only where it is really needed," said senior BJP figure Subramanian Swamy after the ruling.