Complete login function