BATON ROUGE, La. (AP) — A Louisiana private investigator accused of trying to illegally obtain Donald Trump's tax returns is barred from testifying he acted as a benevolent "white hat hacker" attempting to test security flaws in a government website, a federal judge ruled Thursday.

U.S. District Judge James Brady said 32-year-old Jordan Hamlett won't be allowed to tell jurors at a trial set for December that his actions had a "good purpose."

However, defense attorney Michael Fiser can argue Hamlett didn't have any "intent to deceive" — a key element of the criminal charge he faces.

"It's the intent that has to be proved," Fiser said.

Authorities have said Hamlett, a Lafayette resident, failed in his attempts to get Trump's tax returns several weeks before last year's presidential election.

Every president since Jimmy Carter has released their tax returns in what has become an American tradition during presidential elections. Trump has refused to release his.

Hamlett tried "out of sheer curiosity" to discover whether Trump's tax information could be accessed through a weakness in a U.S. Department of Education financial aid website's data retrieval tool, Fiser said in a court filing last week. Fiser also said his client tried to call and notify the IRS about that flaw last September, on the same day he tried to electronically access Trump's tax records.

"Hamlett abandoned the attempt to notify the IRS when he could not reach a human, only recorded messages," Fiser wrote.

Hamlett's trial on a charge he misused a Social Security number is scheduled to start Dec. 4.

Assistant U.S. Attorney Ryan Rezaei asked the judge to bar Hamlett's lawyer from presenting a "white hat" defense at trial. He dismissed that as "essentially nothing more than a belated excuse for a crime." In court Thursday, Rezaei likened it to a bank robber claiming to rob a bank to test its security system.

"That defense, that argument, is never going to be allowed in court," Rezaei said.

Federal agents confronted Hamlett two weeks before last November's election and questioned him in a Baton Rouge hotel lobby. At the time, the agents didn't know if Hamlett had been successful, and they feared a public release of Trump's tax returns could influence the election, according to a transcript of testimony at an earlier hearing in the case.

An agent testified that investigators asked Hamlett if he was familiar with Anonymous, an internet hacking group.

"At that time, Anonymous had been established as people that have released some of President Trump's personal identifying information and things of that nature," added Treasury Department Special Agent Samuel Johnson.

Johnson said Hamlett immediately took credit for his "genius idea" to seek Trump's tax returns from the financial aid website.

Fiser asked the judge Thursday if prosecutors will be barred from trying to link Hamlett to Anonymous or claiming he had any "bad motives."

"That's a call I'll have to make at (trial)," Brady responded.

In a footnote to a court filing, prosecutors explained the distinction between "white hat" and "black hat" hackers. Black hats are "bad guys" who violate computer security for personal gain, while white hats are "good guys" who employ the same methods but do it legally with permission from system owners, they wrote.

Fiser said Hamlett liked to test security systems for weaknesses in his spare time and would notify system administrators if he found a system vulnerable to a security breach.