Improve login function

Use common connection handling
Fix TestCase
Cleanup TestCases
Merge pull request #6 from gengo/improve_login

Improve login function