A US student who committed identity theft to rig an election for president of the student body has been sentenced to a year in prison.

Matthew Weaver stole the passwords of 745 students at California State University San Marcos to cast ballots for himself and friends.

The 22-year-old was one of only two candidates for the main role.

Prosecutors said Weaver had researched the scheme online beforehand and then made a plan to blame others.

He was arrested in February after a year-long investigation and pleaded guilty a month later to wire fraud, unauthorised access of a computer and identity theft.

Caught red-handed

He installed small electronic devices that record a computer's keystrokes in order to steal the passwords, before casting about 630 votes for himself.

Assistant US Attorney Sabrina Feve called Weaver "an incredibly entitled young man".

Sentencing him on Monday, US District Judge Larry Burns said that Weaver had shown "phenomenal misjudgement".

"He's on fire for this crime and then he pours gasoline on it," Judge Burns said, reports the Los Angeles Times.

According to prosecutors, Weaver was caught red-handed.

After university officials received numerous complaints about students being unable to vote, they noticed hundreds of ballots coming from one computer.

As the voting period ended, campus police found Weaver sitting at the machine.

The school cancelled the results of the election for the job, which reportedly comes with an $8,000 (£5,300) stipend.