Login refactoring

This is a fix for all the failing tests