Banning sex offenders from using social media networks like Facebook is unconstitutional, according to a federal court.

The 7th U.S. Circuit Court of Appeals in Chicago struck down an Indiana law passed in 2008 that prohibited certain sex offenders from accessing and using social media networks, if those sites were used by minors. The judges held that such a prohibition was a "blanket ban" that went too far by restricting free speech.

The law "broadly prohibits substantial protected speech rather than specifically targeting the evil of improper communications to minors," the judges wrote in the ruling, according to the Associated Press. "The goal of deterrence does not license the state to restrict far more speech than necessary to target the prospective harm."

A federal judge previously upheld the law, ruling that it was "narrowly tailored" enough that it didn't infringe on the first amendment rights of those convicted of sex offenses. The law was initially challenged by an Indiana resident who claimed it would restrict his free speech rights, forbid him from checking his children's online accounts, advertise his business, and connect with friends and family.

The decision was applauded by Hanni Fakhoury, an attorney with the online rights advocacy group Electronic Frontier Foundation. Fakhoury noted in these cases, even if there are "very compelling interests in protecting children," sometimes the law goes too far.

"The real problem is the methods by which governments are doing it to kind of protect minors from online predators, if you will, are far far far too expansive and not really narrowly tailored to the purpose that they're ostensibly enacting these laws for,” he told Mashable.

The Indiana law tackles the same issues as California's Proposition 35. The Californians Against Sexual Exploitation Act required anyone who is registered as sex offender — which includes those convicted of minor offenses like indecent exposure — to turn over to law enforcement all their online identities, basically prohibiting them from posting online anonymously or with a pseudonym.

On January 12, a judge halted the enforcement of the law, considering it too broad. "The government may not regulate expression in such a manner that a substantial portion of the burden on speech does not serve to advance its goals,” he wrote.

"I think it's good that judges are being kind of critical with what's going on and saying that governments need to really dig in and do some work and narrowly tailor these types of laws so that they don't enact blanket prohibition that prohibit a whole class of people from being able to speak online,” said Fakhoury, who worked on the California case on behalf of the EFF and has also penned an op-ed on Wired, explaining why they are defending the online free speech rights of sex offenders.

The American Civil Liberties Union, which filed the suit along with the Indiana resident, argued that even though the rest of the web would be accessible to these type of sex offenders, social media networks are now indispensable in our digital lives, and that the ban would prevent them from using Facebook or other websites for legitimate uses.

"Indiana already has a law on the books that prohibits inappropriate sexual contacts with children," including penalties for online activities, the ACLU legal director Ken Falk told the Associated Press. "This law sought to criminalize completely innocent conduct that has nothing to do with children."

Apart from the laws in Indiana and California, other states like Nebraska and Louisiana have tried to enact similar regulations and have already encountered opposition in the courts. The one in Nebraska was partially struck down last October, while in Louisiana, the legislators had to pass a narrower statute.

"There is certainly a growing chorus of concern over the constitutional problems of these type of laws," Fakhoury said.

SEE ALSO: Imprisoned Sex Offenders Banned From Facebook

Mashable composite. Photos via iStockphoto, Lebazele