Improve login method

I add some Exception in login() method and also change the function to use default parameters.