Completed login function.