Authentication support

It's an improved version of authentication from pull request #141