Move login cache handling to class

We really want the login method to be wrapped, rather than in external
function.

Signed-off-by: Michal Čihař <michal@cihar.com>