Abstract login into a comprehensive function