almost working login function