A Louisiana private investigator was sentenced Wednesday to 18 months in prison for repeatedly trying to electronically access Donald Trump's federal tax information several weeks before the 2016 election.

Jordan Hamlett, 32, of Lafayette, pleaded guilty in December to misusing Trump's Social Security number. He had faced a maximum sentence of five years in prison and a $250,000 fine when U.S. District Judge John deGravelles sentenced him.

The judge told Hamlett that his sentence 'has nothing to do with the election'.

'This is not about who won, who lost. This is not about politics,' deGravelles added.

Authorities have said Hamlett failed in his attempts to get Trump's tax information through a U.S. Department of Education financial aid website.

Assistant U.S. Attorney Ryan Rezaei had urged the judge to consider what could have happened if Hamlett had succeeded.

Jordan Hamlett (pictured) was sentenced to 18 months in prison for repeatedly trying to access Donald Trump's tax information

'You're talking about potentially altering a presidential election,' the prosecutor said.

Hamlett apologized and told the judge he regrets what he did. He said his actions cost him 'everything', including his career and his home.

'I was trying to help, and I made a bad decision,' he said. 'It was a mistake, and it was a bad decision.'

The judge ordered Hamlett to report to a federal prison by May 28. He also ordered him to pay $14,794 in restitution to the Department of Education to cover the cost of its response to Hamlett's attempts.

Defense attorney Michael Fiser had argued Hamlett didn't have any 'intent to deceive' and tried 'out of sheer curiosity' to discover whether he could access Trump's tax information.

Trump has refused to release his tax returns, bucking an American tradition honored by every president since Jimmy Carter.

Hamlett used Trump's name, Social Security number and date of birth to open an online application for federal student aid in September 2016, according to a court document accompanying his plea agreement. Hamlett also created a phony email address, djtrumpicusmaximus@gmail.com, in his application under Trump's name.

After obtaining a username and password, Hamlett tried to use an Internal Revenue Service data retrieval tool to obtain Trump's tax information, the document says.

Hamlett used Trump's name, Social Security number and date of birth to open an online application for federal student aid in September 2016. Pictured: Trump and wife Melania on April 24

'The defendant made six separate attempts to obtain the federal tax information from IRS servers, but he was unsuccessful,' says the document. It doesn't specify how much of Trump's tax information could have been retrieved with the online tool.

Fiser said Hamlett had tried to call and notify the IRS about the flaws on the same day he tried to electronically access Trump's tax records.

Federal agents confronted Hamlett two weeks before the presidential 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 court testimony.

Treasury Department Special Agent Samuel Johnson testified in March 2017 that Hamlett immediately took credit for his 'genius idea' to seek Trump's tax returns from the financial aid website.

Johnson noted that an internet hacking group calling itself Anonymous had targeted Trump.

'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,' Johnson testified.

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. Hamlett once discovered a security flaw that allowed for public access to the Livingston Parish Sheriff's Office's 'raw' reports on open investigations and exposed personal information about police officers.

'Hamlett tipped the sheriff's office to the flaw and was met with thanks and appreciation, not an arrest,' his attorney wrote in a court filing.

After his November 2016 indictment, Hamlett was arrested again for allegedly violating conditions of his pretrial release. Prosecutors said he committed 'numerous violations,' including hacking into email and social media accounts of a man at the request of the man's wife.