Login refactoring

Change-Id: I12fa6bb37b03bd4f0536aa85b002e72b71db805e