complated auto login function