copied JH's login code

I think it works now...