Consolidate login code