A former security guard at the Calgary courthouse has pleaded guilty to dozens of child pornography, luring and extortion charges.

Daniel Mackie admitted that for years he would befriend boys and girls on internet sites like Facebook, get their passwords and then threaten that if they didn't send him nude photos or videos he would take over their accounts.

And sometimes he would take over their accounts, often contacting their friends or sharing any photos he had succeeded in extorting.

Police first questioned Mackie in 2008 after a teen complained.

The next year, he chatted with an undercover officer posing as a teen and asked for photos.

Yet in 2011, according to court documents, police concluded a teenage boy was lying about having his account hacked.

Months later an officer searched Mackie's name and found he was being investigated for the same kind of crimes.

When Mackie was finally arrested, investigators found that he had 23 different internet chat accounts and 26 email addresses.

Mackie is currently in protective custody at the Calgary Remand Centre. He will be sentenced later this fall.