Refactor authentication code

Refactor auth out into a separate package to make it easier to add more auth mechanisms in future. `PLAIN` login works, but I don't have an account with which I can test `DIGEST-MD5`... can't see why it would have broken though.

This is in preparation for fixing issues #71 and #42 and obsoletes pull #594.