Auth overhaul

See documentation that is part of the pull request for an explanation of the changes.
Thorough tests, questions and discussion is most welcomed.