A 25-year-old Hastings man was charged Thursday with two counts of stalking a former 12-year-old female student, according to the Dakota County attorney's office.

Cody Woodrow Hansen, who was a teacher at an Eagan middle school, allegedly sent numerous messages from November to January via Snapchat to the girl. He has since resigned from his teaching position.

The student had screen shots and saved some of the conversations, and reported them to Eagan police, the county attorney's office said.

"Criminal activity of this nature is a breach of trust of students and is a violation of the law and school policy," Dakota County Attorney James Backstrom said in a statement.

Hansen allegedly used several usernames to contact the student, including variations of his first name spelled backward, during school and the winter holiday break.

In one message, Hansen told the student he thought she was cute. Another asked if she had ever kissed anyone and if she liked older men.

The student didn't know the messages were coming from Hansen until he admitted who he was and that he would get into trouble.

The student told police she "felt creepy and unsafe" in Hansen's classroom.

Hansen told police he sent the messages by finding the student's Snapchat username from her Instagram account. He told police that he is no longer in communication with the student and "hoped this would all go away."

Hansen was charged by summons. His first court appearance has not yet been set.

Karen Zamora • 612-673-4647

Twitter: @KarenAnelZamora