login handling (not perfect, to improve)